Documentation
¶
Index ¶
Constants ¶
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.
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?
type Function ¶
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
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
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 }
type Phase ¶
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
type Print ¶
type Print struct { Message string // if empty, will simply use "%#v" Data []interface{} frame2.Log frame2.DefaultRunDealer }