f2general

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const CmdDefaultTimeout = 2 * time.Minute

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	// The command to be executed, as if exec.Command() had been called (ie, it
	// looks for the command on the PATH, if no slashes on it).  If empty, then
	// Cmd.Path must be set
	Command string
	// The exec.Cmd structure to be run.  If Command above is empty, it will be
	// used as is.  If Command is non-empty,  however, we'll run replace Cmd.Path
	// and Cmd.Args with those returned by exec.Command (ie, we'll let Go find
	// the path to the command).
	exec.Cmd
	Ctx           context.Context
	Timeout       time.Duration // If not provided, a default timeout of 2 min is used
	Shell         bool          // if set, Cmd.Path and Cmd.Args are ignored; use Command under sh -c
	frame2.Expect               // Configures checks on Stdout and Stderr
	AcceptReturn  []int         // consider these return status as a success.  Default only 0
	FailReturn    []int         // Fail on any of these return status.  Default anything other than 0
	ForceOutput   bool          // Shows this command's output on log, regardless of environment config
	ForceNoOutput bool          // No output, regardless of environment config.  Takes precedence over the above

	// Variables to be added or overwritten on the environment.  The entries should be in
	// the form key=value.  When this is non-null, it will be added to the result of os.Environ
	// and used on exec.Cmd (where the last entry of a key takes precedence)
	AdditionalEnv []string

	frame2.Log
	frame2.DefaultRunDealer

	*CmdResult
}

Executes a command locally (ie, on the machine executing the test).

If a CmdResult is provided by the caller, it will be populated with the stdout, stderr and error returned by the exec.Command execution, for further processing.

Yet, most output check should be possible using the provided frame2.Expect configuration.

If both AcceptReturn and FailReturn are defined and the return status is not present on either, an error will be returned

This is basically a wrapper around Go's exec.Cmd, and its configuration even uses that structure, embedded. There are some differences, however:

  • There is a Shell option
  • A timeout can be defined directly, in addition to a Context
  • In case both context and timeout are given, the timeout is applied over the context (ie, a timeout context wrapping the original context)
  • If neither are provided, there is a default timeout. If the user provides their own Context, though, it's up to them to make sure the command does not run forever.

func (*Cmd) Execute

func (c *Cmd) Execute() error

func (*Cmd) Validate

func (c *Cmd) Validate() error

type CmdError

type CmdError struct {
	Cmd    error
	Expect error
}

func (CmdError) Error

func (ce CmdError) Error() string

type CmdResult

type CmdResult struct {
	Stdout string
	Stderr string
	Err    error
}

type Dummy

type Dummy struct {
	Results []error

	frame2.Log
	// contains filtered or unexported fields
}

func (*Dummy) Validate

func (d *Dummy) Validate() error

type Executor

type Executor struct {
	// Make sure your Executor has no side effects when using
	// validate.Executor
	Executor frame2.Executor

	frame2.Log
	frame2.DefaultRunDealer
}

This allows one to use an Executor as a validation, while ensuring that the test step explicitly shows it's using an Executor for validation.

It's on the user to ensure whatever use of an executor they make will not have side effects, as validators are not expected to produce side effects.

If an executor does produce a side effect, do not use this. Put the executor on the Modify of the step (for the side effect, if desired), and use something else to validate.

TODO: as an ergonomy option, add an "Executors []frame2.Executor" and an option for AND or OR on them?

func (*Executor) Validate

func (e *Executor) Validate() error

type Fail

type Fail struct {
	Reason string

	frame2.Log
	frame2.DefaultRunDealer
}

func (Fail) Execute

func (f Fail) Execute() error

func (Fail) Validate

func (f Fail) Validate() error

type Function

type Function struct {
	Fn func() error

	frame2.Log
}

Give it a function, and it will execute. No options, as we can predict what would be needed. If you need input, you'll have to capture it in a closure

func (Function) Execute

func (f Function) Execute() error

func (Function) Validate

func (f Function) Validate() error

type JSON

type JSON struct {
	// The JSON structure to be unmarshalled and analized, in
	// string format
	Data string

	// A list of verifications to be performed against the data
	Matchers []JSONMatcher

	*frame2.Log
}

Inspect a JSON structure using JMESPath

func (JSON) Validate

func (j JSON) Validate() error

type JSONMatcher

type JSONMatcher struct {

	// The JMESPath expression to be executed.  There are
	// currently two way of using it.
	//
	// 1 - An expression that returns a list of booleans,
	//     such as
	//
	//     [?[0] == 'router'] |[].mode | map((&@ == 'edgee'), @)
	//
	//     In this case, all items are verified to be true,
	//     and the length checks are executed.
	//
	//     Use this to validate a value of the JSON structure
	//     has a certain value specified on the JMESPath
	//
	// 2 - An expression that returns a list of any other
	//     types, such as
	//
	//     [?[0] == 'sslProfile']
	//
	//     In this case, NotBoolList must be set to true,
	//     and only the length checks will be run.
	//
	Expression string

	// TODO
	// If set to True, the Expression is expected to return
	// a literal, and min/max/exact checks are not run.  If
	// false, the expression is expected to return a list
	Literal bool

	// If NotBoolList, the content checks are skipped, and
	// only the sizes are verified.
	NotBoolList bool

	// If Exact, Min and Max are all 0, we expect the
	// Expression to return a list with zero elements
	//
	// If Exact and Max are non-zero, only Max is checked
	Exact int

	// Min is inclusive (ie Min==1, then len() must be
	// at least 1)
	Min int

	// If you want any number of elements being returned
	// from the Expression, set Max to math.MaxInt
	//
	// Max is inclusive (ie, if Max=10, then len() must
	// be equal or less than 10)
	Max int

	Response interface{}
}

TODO: perhaps ofer a number of Expressions that matches the JSON types? Something like

StringValue map[string]string IntValue map[string]int BoolValue map[string]bool

Where the key is the search, and the value is the expected value.

Need to work on that interface, but that would be a better match

type MapCheck

type MapCheck struct {

	// List of keys expected to be present on the map, regardless of value
	KeysPresent []string

	// List of keys expected to _not_ be present on the map
	KeysAbsent []string

	// Keys that are expected to be present, with specific values
	Values map[string]string

	// If key is present, it must have the specific value.  A missing key is
	// considered ok
	ValuesOrMissing map[string]string

	// Annotations listed on this map must not have the mapped value.  If the
	// key does not exist at all on the map, the NegativeAnnotations test is
	// considered successful, unless NegativeAnnotationsExist is set to true
	NegativeValues map[string]string

	// If key is present, it must not have the specific value.  A missing key is
	// considered ok
	NegativeValuesOrMissing map[string]string

	// Match regexp against values
	RegexpValues map[string]regexp.Regexp

	MapValidator func(map[string]string) error

	// This is used informationally, on error messages.  It can be anything, such
	// as 'label' or 'annotation'
	MapType string
}

func (MapCheck) Check

func (mc MapCheck) Check(m map[string]string) error

func (MapCheck) CheckBytes

func (mc MapCheck) CheckBytes(m map[string][]byte) error

type Phase

type Phase struct {
	Phase frame2.Phase
	*frame2.Log
	frame2.DefaultRunDealer
}

This frame exists to test frame2 itself

You should be able to use it to do complex validations, but you're probably better off using a simple list of Validators.

On the provided frame2.Phase, do not set the Runner: it will be overridden

func (Phase) Validate

func (p Phase) Validate() error

type Print

type Print struct {
	Message string // if empty, will simply use "%#v"
	Data    []interface{}

	frame2.Log
	frame2.DefaultRunDealer
}

func (Print) Execute

func (p Print) Execute() error

func (Print) Validate

func (p Print) Validate() error

type Success

type Success struct {
	frame2.Log
	frame2.DefaultRunDealer
}

func (Success) Execute

func (s Success) Execute() error

func (Success) Validate

func (s Success) Validate() error

type Wait

type Wait struct {
	Delay time.Duration

	Ctx context.Context
}

Simply waits for the configured duration. If a context is provided and it gets cancelled, the function will return earlier.

func (Wait) Execute

func (w Wait) Execute() error

Jump to

Keyboard shortcuts

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