test

package
v1.6.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

README

Tests

The purpose of this docs is to describe KICS' tests

Getting Started

There are several ways to execute the E2E tests.

TLDR

This command will execute all go tests:

make test-race-cover

This will run a shorter test suite without the queries tests.

make test-short

If you want to generate a HTML coverage report:

make test-coverage-report

Documentation

Index

Constants

View Source
const (
	// ValidUUIDRegex is a constant representing a regular expression rule to validate UUID string
	ValidUUIDRegex = `(?i)^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$`
)

Variables

View Source
var ComplexSummaryMock = model.Summary{
	Counters: model.Counters{
		ScannedFiles:           2,
		ParsedFiles:            2,
		FailedToScanFiles:      0,
		TotalQueries:           2,
		FailedToExecuteQueries: 0,
	},
	Queries: []model.QueryResult{
		queryHigh,
		queryMedium,
	},
	SeveritySummary: model.SeveritySummary{
		ScanID: "console",
		SeverityCounters: map[model.Severity]int{
			model.SeverityInfo:   0,
			model.SeverityLow:    0,
			model.SeverityMedium: 1,
			model.SeverityHigh:   2,
		},
		TotalCounter: 3,
	},
	LatestVersion: model.Version{
		Latest: true,
	},
}

ComplexSummaryMock a summary with more results to be used without running kics scan

View Source
var ExampleSummaryMock = model.Summary{
	Counters: model.Counters{
		ScannedFiles:           2,
		ParsedFiles:            2,
		FailedToScanFiles:      0,
		TotalQueries:           2,
		FailedToExecuteQueries: 0,
	},
	Queries: []model.QueryResult{
		queryInfo,
		queryMedium2,
	},
	SeveritySummary: model.SeveritySummary{
		ScanID: "console",
		SeverityCounters: map[model.Severity]int{
			model.SeverityInfo:   2,
			model.SeverityLow:    0,
			model.SeverityMedium: 1,
			model.SeverityHigh:   0,
		},
		TotalCounter: 3,
	},
	ScannedPaths: []string{
		"./",
	},
}

ExampleSummaryMock a summary with specific results to CycloneDX report tests

View Source
var SimpleSummaryMock = model.Summary{
	Counters: model.Counters{
		ScannedFiles:           1,
		ParsedFiles:            1,
		FailedToScanFiles:      0,
		TotalQueries:           1,
		FailedToExecuteQueries: 0,
	},
	Queries: []model.QueryResult{
		queryMedium,
	},
	SeveritySummary: model.SeveritySummary{
		ScanID: "console",
		SeverityCounters: map[model.Severity]int{
			model.SeverityInfo:   0,
			model.SeverityLow:    0,
			model.SeverityMedium: 1,
			model.SeverityHigh:   0,
		},
		TotalCounter: 1,
	},
	ScannedPaths: []string{
		"./",
	},
}

SimpleSummaryMock a summary with specific results to ASFF report tests

View Source
var SummaryMock = model.Summary{
	Counters: model.Counters{
		ScannedFiles:           1,
		ParsedFiles:            1,
		FailedToScanFiles:      0,
		TotalQueries:           1,
		FailedToExecuteQueries: 0,
	},
	Queries: []model.QueryResult{
		queryHigh,
	},
	SeveritySummary: model.SeveritySummary{
		ScanID: "console",
		SeverityCounters: map[model.Severity]int{
			model.SeverityInfo:   0,
			model.SeverityLow:    0,
			model.SeverityMedium: 0,
			model.SeverityHigh:   2,
		},
		TotalCounter: 2,
	},
	ScannedPaths: []string{
		"./",
	},
}

SummaryMock a summary to be used without running kics scan

Functions

func CaptureCommandOutput

func CaptureCommandOutput(cmd *cobra.Command, args []string) (string, error)

CaptureCommandOutput set cobra command args, if necessary, then capture the output

func CaptureOutput

func CaptureOutput(funcToExec execute) (string, error)

CaptureOutput changes default stdout to intercept into a buffer, converts it to string and returns it

func ChangeCurrentDir

func ChangeCurrentDir(desiredDir string) error

ChangeCurrentDir gets current working directory and changes to its parent until finds the desired directory or fail

func GetCurrentDirName

func GetCurrentDirName(path string) string

GetCurrentDirName returns current working directory

func MapToStringSlice added in v1.2.0

func MapToStringSlice(stringKeyMap map[string]string) []string

MapToStringSlice extract slice of keys from a map[string]string

func StringifyStruct added in v1.1.3

func StringifyStruct(v interface{}) (string, error)

StringifyStruct stringify struct for pretty print

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL