framework

package
v0.1.0-M3 Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: Apache-2.0, EPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const TestData = "testdata"

TestData constant for the testdata directory.

Variables

This section is empty.

Functions

func AddCustomResult

func AddCustomResult(name string, f func(result icmd.Result, args ...string) assert.BoolOrComparison) error

AddCustomResult adds custom result to customResultFns map or returns an error.

func GetAllTestCasesFromTestdataDir

func GetAllTestCasesFromTestdataDir() (map[string][]TestCaseCMD, error)

GetAllTestCasesFromTestdataDir reads all files that matches the "*-test.yaml" and parses them to TestCaseCMD map.

func RunCmdTestCases

func RunCmdTestCases(t *testing.T, cmdList []TestCaseCMD)

RunCmdTestCases runs the provided test cases and asserts the result according to the provided parameters.

Types

type Command

type Command struct {
	Binary string   `yaml:"binary"`
	Args   []string `yaml:"args"`
}

Command is contains the binary and arguments that will run in the test case.

type CustomResult

type CustomResult struct {
	Type string   `yaml:"type"`
	Args []string `yaml:"args"`
}

CustomResult is a representation of a "func(result icmd.Result, args ...string) assert.BoolOrComparison" where Name is the name of the function and Args... are optional string arguments that the function may use. If CustomResult function is defined the result of the icmd.Cmd that is executed will be asserted to that CustomResult function. CustomResult functions can be passed as an argument to the runCmdTestCases(...) or one of the default functions can be used.

Default functions:

  • REGEX - this function will compare the stdout or stderr outputs from the result with the regex provided to args[0]. example: customResult: name: REGEX args: ["([A-Za-z0-9]+(-[A-Za-z0-9]+)+)"]
  • LOGS_JSON - this function will validate that the stdout outputs consist of valid JSON entries and compare their count to args[0] if provided. example: customResult: name: LOGS_JSON args: ["5"]

type Expected

type Expected struct {
	ExitCode int    `yaml:"exitCode"`
	Timeout  bool   `yaml:"timeout"`
	Error    string `yaml:"error"`
	Out      string `yaml:"out"`
	Err      string `yaml:"err"`
}

Expected is the expected output from a Command.

type TestCaseCMD

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

TestCaseCMD represents a command and expected result.

func GetTestCaseFromYamlFile

func GetTestCaseFromYamlFile(filePath string) ([]TestCaseCMD, error)

GetTestCaseFromYamlFile parses yaml file to TestCaseCMD array.

type TestCommand

type TestCommand struct {
	GoldenFile   string       `yaml:"goldenFile"`
	Name         string       `yaml:"name"`
	Command      Command      `yaml:"command"`
	Expected     Expected     `yaml:"expected"`
	CustomResult CustomResult `yaml:"customResult"`
	Setup        *[]Command   `yaml:"setupCmd"`
	OnExit       *[]Command   `yaml:"onExit"`
}

TestCommand defines all required and optional features that are needed for CLI integration test.

Jump to

Keyboard shortcuts

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