testing

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 23 Imported by: 1

Documentation

Index

Constants

View Source
const (
	RULESET_TEST_CONFIG_GOLDEN_FILE = "testing-config.yaml"
)

Variables

This section is empty.

Functions

func AnyFailed

func AnyFailed(results []Result) bool

func GenerateTestsSchema

func GenerateTestsSchema() (*openapi3.SchemaRef, error)

func PrintProgress

func PrintProgress(w io.WriteCloser, results []Result)

PrintProgress prints detailed information from given results

func PrintSummary

func PrintSummary(w io.WriteCloser, results []Result)

PrintSummary prints statistical summary from given results

Types

type AnalysisParams

type AnalysisParams struct {
	// Mode analysis mode to use when running the test, one of - source-only, full
	Mode provider.AnalysisMode `yaml:"mode,omitempty" json:"mode,omitempty"`
	// DepLabelSelector dependency label selector to use when running the test
	DepLabelSelector string `yaml:"depLabelSelector,omitempty" json:"depLabelSelector,omitempty"`
}

func (AnalysisParams) Validate

func (a AnalysisParams) Validate() error

type CountBasedVerification

type CountBasedVerification struct {
	// Exactly pass test case when there are exactly this many incidents
	Exactly *int `yaml:"exactly,omitempty" json:"exactly,omitempty"`
	// AtLeast pass test case when there are this many or more incidents
	AtLeast *int `yaml:"atLeast,omitempty" json:"atLeast,omitempty"`
	// AtMost pass test case when there are no more than this many incidents
	AtMost *int `yaml:"atMost,omitempty" json:"atMost,omitempty"`
	// MessageMatches pass test case when all incidents contain this message
	MessageMatches *string `yaml:"messageMatches,omitempty" json:"messageMatches,omitempty"`
	// CodeSnipMatches pass test case when all incidents contain this code snip
	CodeSnipMatches *string `yaml:"codeSnipMatches,omitempty" json:"codeSnipMatches,omitempty"`
}

CountBasedVerification defines test case passing criteria based on count of incidents. Only one of exactly, atLeast, or atMost can be defined at a time.

type IncidentVerification

type IncidentVerification struct {
	// CountBased defines a simple test case passing criteria based on count of incidents
	CountBased *CountBasedVerification `yaml:",inline,omitempty" json:",inline,omitempty"`
	// LocationBased defines a detailed test case passing criteria based on each incident
	LocationBased *LocationBasedVerification `yaml:",inline,omitempty" json:",inline,omitempty"`
}

IncidentVerification defines criterias to pass a test case. Only one of CountBased or LocationBased can be defined at a time.

func (*IncidentVerification) MarshalYAML

func (i *IncidentVerification) MarshalYAML() (interface{}, error)

func (IncidentVerification) Validate

func (t IncidentVerification) Validate() error

type LocationBasedVerification

type LocationBasedVerification struct {
	// Locations defines detailed conditions for each incident
	Locations []LocationVerification `yaml:"locations" json:"locations"`
}

type LocationVerification

type LocationVerification struct {
	// FileURI is the file in which incident is supposed to be found
	FileURI *string `yaml:"fileURI,omitempty" json:"fileURI,omitempty"`
	// LineNumber is the line number where incident is supposed to be found
	LineNumber *int `yaml:"lineNumber,omitempty" json:"lineNumber,omitempty"`
	// MessageMatches is the message that's supposed to be contained within the message of this incident
	MessageMatches *string `yaml:"messageMatches,omitempty" json:"messageMatches,omitempty"`
	// CodeSnipMatches is the code snippet which is supposed to be present within the codeSnip of this incident
	CodeSnipMatches *string `yaml:"codeSnipMatches,omitempty" json:"codeSnipMatches,omitempty"`
}

LocationVerification defines test case passing criteria based on detailed information in an incident. FileURI and LineNumber are required.

func (LocationVerification) Validate

func (l LocationVerification) Validate() error

type ProviderConfig

type ProviderConfig struct {
	// Name is the name of the provider this config applies to
	Name string `yaml:"name" json:"name"`
	// DataPath is a relative path to test data to be used for this provider
	DataPath string `yaml:"dataPath" json:"dataPath"`
}

func (ProviderConfig) Validate

func (p ProviderConfig) Validate() error

type Result

type Result struct {
	Passed         bool
	TestsFilePath  string
	RuleID         string
	TestCaseName   string
	DebugInfo      []string
	FailureReasons []string
	Error          error
}

Result is a result of a test run

type ResultPrinter

type ResultPrinter func(io.WriteCloser, []Result)

ResultPrinter is a function to print given results to a given place

type Runner

type Runner interface {
	Run([]TestsFile, TestOptions) ([]Result, error)
}

Runner given a list of TestsFile and a TestOptions runs the tests, computes and returns results

func NewRunner

func NewRunner() Runner

type Test

type Test struct {
	// RuleID is the ID of the rule this test applies to
	RuleID string `yaml:"ruleID" json:"ruleID"`
	// TestCases is a list of distinct test cases for this rule
	TestCases []TestCase `yaml:"testCases" json:"testCases"`
}

func (Test) Validate

func (t Test) Validate() error

type TestCase

type TestCase struct {
	// Name is a unique name for this test case
	Name string `yaml:"name" json:"name"`
	// AnalysisParams is analysis parameters to be used when running this test case
	AnalysisParams `yaml:"analysisParams,omitempty" json:"analysisParams,omitempty"`
	// IsUnmatched passes test case when the rule is not matched
	IsUnmatched bool `yaml:"isUnmatched,omitempty" json:"isUnmatched,omitempty"`
	// HasIncidents defines criteria to pass the test case based on incidents for this rule
	HasIncidents *IncidentVerification `yaml:"hasIncidents,omitempty" json:"hasIncidents,omitempty"`
	// HasTags passes test case when all of the given tags are generated
	HasTags []string `yaml:"hasTags,omitempty" json:"hasTags,omitempty"`
	RuleID  string   `yaml:"-" json:"-"`
}

func (TestCase) Validate

func (t TestCase) Validate() error

func (TestCase) Verify

func (t TestCase) Verify(output konveyor.RuleSet) []string

type TestOptions

type TestOptions struct {
	TempDir            string
	LoudOutput         bool
	BaseProviderConfig []provider.Config
	RunLocal           bool
	ContainerImage     string
	ProgressPrinter    ResultPrinter
	Log                logr.Logger
}

type TestsFile

type TestsFile struct {
	// RulesPath is an optional path to respective rules file
	RulesPath string `yaml:"rulesPath,omitempty" json:"rulesPath,omitempty"`
	// Providers is a list of configs with each item containing config specific to a provider
	Providers []ProviderConfig `yaml:"providers,omitempty" json:"providers,omitempty"`
	// Tests is a list of tests with each item defining one or more test cases specific to a rule
	Tests []Test `yaml:"tests,omitempty" json:"tests,omitempty"`
	Path  string `yaml:"-" json:"-"`
}

func Parse

func Parse(paths []string, filter TestsFilter) ([]TestsFile, error)

func (TestsFile) Validate

func (t TestsFile) Validate() error

type TestsFilter

type TestsFilter interface {
	Filter([]Test) []Test
}

TestsFilter filters in-out tests/test cases and returns final list of things to run

func NewInlineNameBasedFilter

func NewInlineNameBasedFilter(names string) TestsFilter

NewInlineNameBasedFilter works on an input string containing a comma separated list of test names and test case names to include

Jump to

Keyboard shortcuts

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