e2e

package module
v0.0.0-...-35696f1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

README

E2E tests

VMClarity's end-to-end tests use the Ginkgo test framework and the Gomega matcher/assertion library to leverage behavior driven testing (BDD).

This test module is composed by:

  • a testenv.go file where the test environment is configured,
  • a docker-compose.override.yml file which will merge and override the installation compose file to run end-to-end tests,
  • a suite_test.go file where the steps to perform the setup and cleanup of the Ginkgo test suite are defined,
  • a helper.go file where common methods are defined,
  • and test case files.

Run test

To run all end-to-end tests, use the following command:

go test -v -failfast -test.v -test.paniconexit0 -timeout 2h -ginkgo.v .

To run a particular end-to-end test file, use:

go test -v -failfast -test.v -test.paniconexit0 -timeout 2h -ginkgo.v --ginkgo.focus-file <go test file> .

Write a new test

To add a new test, create a new <test_name>_test.go file in the current directory and use the following template:

var _ = ginkgo.Describe("<add a brief test case description>", func() {
    reportFailedConfig := ReportFailedConfig{}
    ginkgo.Context("<describe conditions or inputs>", func() {
        ginkgo.It("<describe the behaviour or feature being tested>", func(ctx ginkgo.SpecContext) {
            <implement test code>
        })
    })
    ginkgo.AfterEach(func(ctx ginkgo.SpecContext) {
        if ginkgo.CurrentSpecReport().Failed() {
            reportFailedConfig.startTime = ginkgo.CurrentSpecReport().StartTime
            ReportFailed(ctx, testEnv, client, &reportFailedConfig)
        }
    })
})

Additionally, check the available test cases (e.g. basic_scan_test.go) to get started.

Documentation

Index

Constants

View Source
const DefaultTimeout = 60 * time.Second

Variables

View Source
var FullScanFamiliesConfig = apitypes.ScanFamiliesConfig{
	Exploits: &apitypes.ExploitsConfig{
		Enabled: to.Ptr(true),
	},
	InfoFinder: &apitypes.InfoFinderConfig{
		Enabled: to.Ptr(true),
	},

	Malware: &apitypes.MalwareConfig{
		Enabled: to.Ptr(false),
	},
	Misconfigurations: &apitypes.MisconfigurationsConfig{
		Enabled: to.Ptr(true),
	},
	Rootkits: &apitypes.RootkitsConfig{
		Enabled: to.Ptr(true),
	},
	Sbom: &apitypes.SBOMConfig{
		Enabled: to.Ptr(true),
	},
	Secrets: &apitypes.SecretsConfig{
		Enabled: to.Ptr(true),
	},
	Vulnerabilities: &apitypes.VulnerabilitiesConfig{
		Enabled: to.Ptr(true),
	},
}

Functions

func DumpAPIData

func DumpAPIData(ctx ginkgo.SpecContext, client *apiclient.Client, config *ReportFailedConfig)

nolint:cyclop DumpAPIData prints API objects filtered using test parameters (e.g. assets filtered by scope, scan configs filtered by id). If filter not provided, no objects are printed.

func DumpServiceLogs

func DumpServiceLogs(ctx ginkgo.SpecContext, testEnv types.Environment, config *ReportFailedConfig)

DumpServiceLogs prints service logs since the test started until it failed.

func GetCustomScanConfig

func GetCustomScanConfig(scanFamiliesConfig *apitypes.ScanFamiliesConfig, scope string, timeoutSeconds int) apitypes.ScanConfig

func GetFullScanConfig

func GetFullScanConfig(scope string, timeout time.Duration) apitypes.ScanConfig

func ReportFailed

func ReportFailed(ctx ginkgo.SpecContext, testEnv types.Environment, client *apiclient.Client, config *ReportFailedConfig)

ReportFailed gathers relevant API data and docker service logs for debugging purposes.

func UpdateScanConfigToStartNow

func UpdateScanConfigToStartNow(config *apitypes.ScanConfig) *apitypes.ScanConfig

Types

type APIObject

type APIObject struct {
	// contains filtered or unexported fields
}

type ReportFailedConfig

type ReportFailedConfig struct {
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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