generic

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: GPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package generic provides a simplified interface for creating a tnf.Test and corresponding reel.Handler from generic JSON input. This exposes the ability for test writers to create tests using only JSON.

Index

Constants

View Source
const (
	// TestSchemaFileName is the filename of the generic test JSON schema.
	TestSchemaFileName = "generic-test.schema.json"
)

Variables

This section is empty.

Functions

func NewGenericFromJSONFile

func NewGenericFromJSONFile(filename, schemaPath string) (*tnf.Tester, []reel.Handler, *gojsonschema.Result, error)

NewGenericFromJSONFile instantiates and initializes a Generic from a JSON-serialized file.

Types

type Generic

type Generic struct {

	// Arguments is the Unix command array.  Arguments is optional;  a command can also be issued using ReelFirstStep.
	Arguments []string `json:"arguments,omitempty" yaml:"arguments,omitempty"`

	// Identifier is the tnf.Test specific test identifier.
	Identifier identifier.Identifier `json:"identifier" yaml:"identifier"`

	// Description is a textual description of the overall functionality that is tested.
	Description string `json:"description,omitempty" yaml:"description,omitempty"`

	// FailureReason optionally stores extra information pertaining to why the test failed.
	FailureReason string `json:"failureReason,omitempty" yaml:"failureReason,omitempty"`

	// Matches contains an in order array of matches.
	Matches []Match `json:"matches,omitempty" yaml:"matches,omitempty"`

	// ReelFirstStep is the first Step returned by reel.ReelFirst().
	ReelFirstStep *reel.Step `json:"reelFirstStep,omitempty" yaml:"reelFirstStep,omitempty"`

	// ReelFirstStep is the first Step returned by reel.ReelFirst().
	ReelMatchStep *reel.Step `json:"reelMatchStep,omitempty" yaml:"reelMatchStep,omitempty"`

	// ResultContexts provides the ability to make assertion.Assertions based on the given pattern matched.
	ResultContexts []*ResultContext `json:"resultContexts,omitempty" yaml:"resultContexts,omitempty"`

	// ReelTimeoutStep is the reel.Step to take upon timeout.
	ReelTimeoutStep *reel.Step `json:"reelTimeoutStep,omitempty" yaml:"reelTimeoutStep,omitempty"`

	// TestResult is the result of running the tnf.Test.  0 indicates SUCCESS, 1 indicates FAILURE, 2 indicates ERROR.
	TestResult int `json:"testResult" yaml:"testResult"`

	// TestTimeout prevents the Test from running forever.
	TestTimeout time.Duration `json:"testTimeout,omitempty" yaml:"testTimeout,omitempty"`
	// contains filtered or unexported fields
}

Generic is a construct for defining an arbitrary simple test with prescriptive confines. Essentially, the definition of the state machine for a Generic reel.Handler is restricted in this facade, since most common use cases do not need to perform too much heavy lifting that would otherwise require a Custom reel.Handler implementation. Although Generic is exported for serialization reasons, it is recommended to instantiate new instances of Generic using NewGenericFromJSONFile, is tailored to properly initialize a Generic.

func (*Generic) Args

func (g *Generic) Args() []string

Args returns the command line arguments as an array of type string.

func (*Generic) GetIdentifier

func (g *Generic) GetIdentifier() identifier.Identifier

GetIdentifier returns the tnf.Test specific identifier.

func (*Generic) GetMatches

func (g *Generic) GetMatches() []Match

GetMatches extracts all Matches.

func (*Generic) ReelEOF

func (g *Generic) ReelEOF()

ReelEOF informs of the eof event.

func (*Generic) ReelFirst

func (g *Generic) ReelFirst() *reel.Step

ReelFirst returns the first step to perform.

func (*Generic) ReelMatch

func (g *Generic) ReelMatch(pattern, before, match string) *reel.Step

ReelMatch informs of a match event, returning the next step to perform.

func (*Generic) ReelTimeout

func (g *Generic) ReelTimeout() *reel.Step

ReelTimeout informs of a timeout event, returning the next step to perform.

func (*Generic) Result

func (g *Generic) Result() int

Result returns the test result.

func (*Generic) Timeout

func (g *Generic) Timeout() time.Duration

Timeout returns the test timeout.

type Match

type Match struct {

	// Pattern is the pattern causing a match in reel.Handler ReelMatch.
	Pattern string `json:"pattern,omitempty" yaml:"pattern,omitempty"`

	// Before contains all output preceding Match.
	Before string `json:"before,omitempty" yaml:"before,omitempty"`

	// Match is the matched string.
	Match string `json:"match,omitempty" yaml:"match,omitempty"`
}

Match follows the Container design pattern, and is used to store the arguments to a reel.Handler's ReelMatch function in a single data transfer object.

type ResultContext

type ResultContext struct {

	// Pattern is the pattern causing a match in reel.Handler ReelMatch.
	Pattern string `json:"pattern,omitempty" yaml:"pattern,omitempty"`

	// ComposedAssertions is a means of making many assertion.Assertion claims about the match.
	ComposedAssertions []assertion.Assertions `json:"composedAssertions,omitempty" yaml:"composedAssertions,omitempty"`

	// DefaultResult is the result of the test.  This is only used if ComposedAssertions is not provided.
	DefaultResult int `json:"defaultResult,omitempty" yaml:"defaultResult,omitempty"`

	// NextStep is an optional next step to take after an initial ReelMatch.
	NextStep *reel.Step `json:"nextStep,omitempty" yaml:"nextStep,omitempty"`

	// NextResultContexts is an optional array which provides the ability to make assertion.Assertions based on the next pattern match.
	NextResultContexts []*ResultContext `json:"nextResultContexts,omitempty" yaml:"nextResultContexts,omitempty"`
}

ResultContext evaluates the Result for a given Match. If ComposedAssertions is not supplied, then Result is assigned to the reel.Handler result. If ComposedAssertions is supplied, then the ComposedAssertions are evaluated against the match. The result of ComposedAssertions evaluation is assigned to the reel.Handler's result.

func (*ResultContext) MarshalJSON

func (r *ResultContext) MarshalJSON() ([]byte, error)

MarshalJSON is a shim provided over the default implementation that omits empty NextResultContexts slices. This custom MarshallJSON implementation is needed due to a recursive definition (type ResultContext has a property of type ResultContext).

Directories

Path Synopsis
Package assertion defines the ability for users to include assertions on the regular expression matched in ReelMatch.
Package assertion defines the ability for users to include assertions on the regular expression matched in ReelMatch.
Package condition defines the Condition Evaluate contract.
Package condition defines the Condition Evaluate contract.
intcondition
Package intcondition exposes some common integer condition implementations.
Package intcondition exposes some common integer condition implementations.
stringcondition
Package stringcondition exposes some common string condition implementations.
Package stringcondition exposes some common string condition implementations.

Jump to

Keyboard shortcuts

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