test

package
v0.0.0-...-aac4589 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetResult

func GetResult(targets map[*target.Target]error, ignore []*target.Target, expression string) (*comparison.Result, error)

GetResult evaluates the success of list of Targets based on a comparison expression

func RegisterFunction

func RegisterFunction(name string, fn interface{}) error

RegisterFunction registers a template function suitable for text/template. It can be either a func(string) string or a func(string) (string, error), hence it's passed as an empty interface.

func UnregisterFunction

func UnregisterFunction(name string) error

UnregisterFunction unregisters a previously registered function

Types

type Param

type Param struct {
	json.RawMessage
}

Param represents a test step parameter. It is initialized from JSON, and can be a string or a more complex JSON structure. Plugins are expected to know which one they expect and use the provided convenience functions to obtain either the string or json.RawMessage representation.

func NewParam

func NewParam(s string) *Param

NewParam inititalizes a new Param object directly from a string. Note that no validation is performed if the input is actually valid JSON.

func (*Param) Expand

func (p *Param) Expand(target *target.Target) (string, error)

Expand evaluates the raw expression and applies the necessary manipulation, if any.

func (Param) IsEmpty

func (p Param) IsEmpty() bool

IsEmpty returns true if the original raw string is empty, false otherwise.

func (Param) JSON

func (p Param) JSON() json.RawMessage

JSON returns the parameter as json.RawMessage for further unmarshalling by the test plugin.

func (Param) String

func (p Param) String() string

String returns the parameter as a string. This helper never fails. If the underlying JSON cannot be unmarshalled into a simple string, this function returns a string representation of the JSON structure.

type ParamExpander

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

func NewParamExpander

func NewParamExpander(target *target.Target) *ParamExpander

func (*ParamExpander) Expand

func (pe *ParamExpander) Expand(value string) (string, error)

func (*ParamExpander) ExpandObject

func (pe *ParamExpander) ExpandObject(obj interface{}, out interface{}) error

type ParameterFunc

type ParameterFunc func(string) string

ParameterFunc is a function type called on parameters that need further validation or manipulation. It is currently used by GetFunc and GetOneFunc.

type Test

type Test struct {
	Name                string
	TestStepsBundles    []TestStepBundle
	TargetManagerBundle *target.TargetManagerBundle
	TestFetcherBundle   *TestFetcherBundle
}

Test describes a test definition.

type TestDescriptor

type TestDescriptor struct {
	// TargetManager-related parameters
	TargetManagerName              string
	TargetManagerAcquireParameters json.RawMessage
	TargetManagerReleaseParameters json.RawMessage

	// TestFetcher-related parameters
	TestFetcherName            string
	TestFetcherFetchParameters json.RawMessage
}

TestDescriptor models the JSON encoded blob which is given as input to the job creation request. The test descriptors are part of the main JobDescriptor JSON document.

func (*TestDescriptor) Validate

func (d *TestDescriptor) Validate() error

Validate performs sanity checks on the Descriptor

type TestFetcher

type TestFetcher interface {
	ValidateFetchParameters(xcontext.Context, []byte) (interface{}, error)
	Fetch(xcontext.Context, interface{}) (string, []*TestStepDescriptor, error)
}

TestFetcher is an interface used to get the test to run on the selected hosts.

type TestFetcherBundle

type TestFetcherBundle struct {
	TestFetcher     TestFetcher
	FetchParameters interface{}
}

TestFetcherBundle bundles the selected TestFetcher together with its acquire and release parameters based on the content of the job descriptor

type TestFetcherFactory

type TestFetcherFactory func() TestFetcher

TestFetcherFactory is a type representing a function which builds a TestFetcher

type TestFetcherLoader

type TestFetcherLoader func() (string, TestFetcherFactory)

TestFetcherLoader is a type representing a function which returns all the needed things to be able to load a TestFetcher

type TestStep

type TestStep interface {
	// Name returns the name of the step
	Name() string
	// Run runs the test step. The test step is expected to be synchronous.
	Run(ctx xcontext.Context, ch TestStepChannels, params TestStepParameters, ev testevent.Emitter,
		resumeState json.RawMessage) (json.RawMessage, error)
	// ValidateParameters checks that the parameters are correct before passing
	// them to Run.
	ValidateParameters(ctx xcontext.Context, params TestStepParameters) error
}

TestStep is the interface that all steps need to implement to be executed by the TestRunner

type TestStepBundle

type TestStepBundle struct {
	TestStep      TestStep
	TestStepLabel string
	Parameters    TestStepParameters
	AllowedEvents map[event.Name]bool
}

TestStepBundle bundles the selected TestStep together with its parameters as specified in the Test descriptor fetched by the TestFetcher

type TestStepChannels

type TestStepChannels struct {
	In  <-chan *target.Target
	Out chan<- TestStepResult
}

TestStepChannels represents the input and output channels used by a TestStep to communicate with the TestRunner

type TestStepDescriptor

type TestStepDescriptor struct {
	Name       string
	Label      string
	Parameters TestStepParameters
}

TestStepDescriptor is the definition of a test step matching a test step configuration.

type TestStepFactory

type TestStepFactory func() TestStep

TestStepFactory is a type representing a function which builds a TestStep. TestStep factories are registered in the plugin registry.

type TestStepLoader

type TestStepLoader func() (string, TestStepFactory, []event.Name)

TestStepLoader is a type representing a function which returns all the needed things to be able to load a TestStep.

type TestStepParameters

type TestStepParameters map[string][]Param

TestStepParameters represents the parameters that a TestStep should consume according to the Test descriptor fetched by the TestFetcher

func (TestStepParameters) Get

func (t TestStepParameters) Get(k string) []Param

Get returns the value of the requested parameter. A missing item is not distinguishable from an empty value. For this you need to use the regular map accessor.

func (TestStepParameters) GetInt

func (t TestStepParameters) GetInt(k string) (int64, error)

GetInt works like GetOne, but also tries to convert the string to an int64, and returns an error if this fails.

func (TestStepParameters) GetOne

func (t TestStepParameters) GetOne(k string) *Param

GetOne returns the first value of the requested parameter. If the parameter is missing, an empty string is returned.

type TestStepResult

type TestStepResult struct {
	Target *target.Target
	Err    error
}

TestStepResult is used by TestSteps to report result for a particular target. Empty Err means success, non-empty indicates failure. Failed targets do not proceed to further steps in this run.

type TestStepStatus

type TestStepStatus string

TestStepStatus represent a blob containing status information that the TestStep can persist into storage to support resuming the test.

type TestStepsDescriptors

type TestStepsDescriptors struct {
	TestName  string
	TestSteps []*TestStepDescriptor
}

TestStepsDescriptors bundles together description of the test step which constitute each test

Jump to

Keyboard shortcuts

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