schelpers

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultScorecardVersion = v1alpha1
View Source
const LatestScorecardVersion = v1alpha2
View Source
const VersionOpt = "version"

Variables

Functions

func CalculateResult

CalculateResult returns a ScorecardSuiteResult with the state and Tests fields set based on a slice of ScorecardTestResults

func IsLatestVersion added in v0.11.0

func IsLatestVersion() bool

func IsV1alpha2 added in v0.11.0

func IsV1alpha2() bool

func TestResultToScorecardTestResult

func TestResultToScorecardTestResult(tr TestResult) scapiv1alpha1.ScorecardTestResult

TestResultToScorecardTestResult is a helper function for converting from the TestResult type to the ScorecardTestResult type

func TestSuitesToScorecardOutput

func TestSuitesToScorecardOutput(suites []TestSuite, log string) scapiv1alpha1.ScorecardOutput

TestSuitesToScorecardOutput takes an array of test suites and generates a v1alpha1 ScorecardOutput object with the provided suites and log

func UpdateState

UpdateState updates the state of a TestResult.

func UpdateSuiteStates

UpdateSuiteStates update the state of each test in a suite and updates the count to the suite's states to match

func ValidateVersion added in v0.11.0

func ValidateVersion(version string) error

Types

type Test

type Test interface {
	GetName() string
	GetDescription() string
	IsCumulative() bool
	Run(context.Context) *TestResult
}

Test provides methods for running scorecard tests

type TestInfo

type TestInfo struct {
	Name        string
	Description string
	// If a test is set to cumulative, the scores of multiple runs of the same test on separate CRs are added together for the total score.
	// If cumulative is false, if any test failed, the total score is 0/1. Otherwise 1/1.
	Cumulative bool
}

TestInfo contains information about the scorecard test

func (TestInfo) GetDescription

func (i TestInfo) GetDescription() string

GetDescription returns the test description

func (TestInfo) GetName

func (i TestInfo) GetName() string

GetName return the test name

func (TestInfo) IsCumulative

func (i TestInfo) IsCumulative() bool

IsCumulative returns true if the test's scores are intended to be cumulative

type TestResult

type TestResult struct {
	State         scapiv1alpha1.State
	Test          Test
	EarnedPoints  int
	MaximumPoints int
	Suggestions   []string
	Errors        []error
}

TestResult contains a test's points, suggestions, and errors

func ResultsCumulative

func ResultsCumulative(results []TestResult) (TestResult, error)

ResultsCumulative takes multiple TestResults and returns a single TestResult with MaximumPoints equal to the sum of the MaximumPoints of the input and EarnedPoints as the sum of EarnedPoints of the input

func ResultsPassFail

func ResultsPassFail(results []TestResult) (TestResult, error)

ResultsPassFail combines multiple test results and returns a single test results with 1 maximum point and either 0 or 1 earned points

type TestSuite

type TestSuite struct {
	TestInfo
	Tests       []Test
	TestResults []TestResult
	Weights     map[string]float64
	Log         string
}

TestSuite contains a list of tests and results, along with the relative weights of each test. Also can optionally contain a log

func MergeSuites

func MergeSuites(suites []TestSuite) ([]TestSuite, error)

MergeSuites takes an array of TestSuites and combines all suites with the same name

func NewTestSuite

func NewTestSuite(name, description string) *TestSuite

NewTestSuite returns a new TestSuite with a given name and description

func (*TestSuite) AddTest

func (ts *TestSuite) AddTest(t Test, weight float64)

AddTest adds a new Test to a TestSuite along with a relative weight for the new Test

func (*TestSuite) Run

func (ts *TestSuite) Run(ctx context.Context)

Run runs all Tests in a TestSuite

func (*TestSuite) TotalScore

func (ts *TestSuite) TotalScore() (score int)

TotalScore calculates and returns the total score of all run Tests in a TestSuite

Jump to

Keyboard shortcuts

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