runtime

package
v2.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExitCode  = "ExitCode"
	Stdout    = "Stdout"
	Stderr    = "Stderr"
	LineCount = "LineCount"
)

Constants for defining the various tested properties

Variables

This section is empty.

Functions

func WithIdentityFile

func WithIdentityFile(identityFile string) func(e *SSHExecutor)

WithIdentityFile sets the identity file option for the ssh executor

func WithPassword

func WithPassword(pass string) func(e *SSHExecutor)

WithPassword sets the identity file option for the ssh executor

Types

type CommandResult

type CommandResult struct {
	Status            ResultStatus
	Stdout            string
	Stderr            string
	ExitCode          int
	FailureProperties []string
	Error             error
}

CommandResult holds the result for a specific test

type CommandUnderTest

type CommandUnderTest struct {
	Cmd        string
	InheritEnv bool
	Env        map[string]string
	Dir        string
	Timeout    string
	Retries    int
	Interval   string
}

CommandUnderTest represents the command under test

func (*CommandUnderTest) GetRetries

func (c *CommandUnderTest) GetRetries() int

GetRetries returns the retries of the command

type DockerExecutor

type DockerExecutor struct {
	Image        string // Image which is started to execute the test
	Privileged   bool   // Enable privileged mode for the container
	ExecUser     string // ExecUser defines which user executes the docker container
	RegistryUser string
	RegistryPass string
}

DockerExecutor executes the test inside a docker container

func (DockerExecutor) Execute

func (e DockerExecutor) Execute(test TestCase) TestResult

Execute executes the script inside a docker container

type EventHandler

type EventHandler struct {
	TestFinished func(TestResult)
	TestSkipped  func(TestResult)
}

EventHandler is a configurable event system that handles events such as test completion

type Executor

type Executor interface {
	Execute(test TestCase) TestResult
}

Executor interface which will be implemented by all available executors, like ssh or local

func NewLocalExecutor

func NewLocalExecutor() Executor

NewLocalExecutor creates a new local executor

func NewSSHExecutor

func NewSSHExecutor(host string, user string, opts ...func(e *SSHExecutor)) Executor

NewSSHExecutor creates a new executor

type Expected

type Expected struct {
	Stdout    ExpectedOut
	Stderr    ExpectedOut
	LineCount int
	ExitCode  int
}

Expected is the expected output of the command under test

type ExpectedOut

type ExpectedOut struct {
	Contains    []string          `yaml:"contains,omitempty"`
	Lines       map[int]string    `yaml:"lines,omitempty"`
	Exactly     string            `yaml:"exactly,omitempty"`
	LineCount   int               `yaml:"line-count,omitempty"`
	NotContains []string          `yaml:"not-contains,omitempty"`
	JSON        map[string]string `yaml:"json,omitempty"`
	XML         map[string]string `yaml:"xml,omitempty"`
	File        string            `yaml:"file,omitempty"`
}

ExpectedOut represents the assertions on stdout and stderr

type Filters

type Filters []string

type GlobalTestConfig

type GlobalTestConfig struct {
	Env        map[string]string
	Dir        string
	Timeout    string
	Retries    int
	Interval   string
	InheritEnv bool
	Nodes      []string
}

GlobalTestConfig represents the configuration for a test

type LocalExecutor

type LocalExecutor struct {
}

LocalExecutor will be used to execute tests on the local host

func (LocalExecutor) Execute

func (e LocalExecutor) Execute(test TestCase) TestResult

Execute will execute the given test on the current node

type Node

type Node struct {
	Name           string
	Type           string
	User           string
	Pass           string
	Addr           string
	Image          string
	IdentityFile   string
	Privileged     bool
	DockerExecUser string
}

Node represents a configured node with everything needed to connect to the given host which is defined in the type property If the type is not available the test will fail and stop its execution

func (*Node) ExpandEnv

func (n *Node) ExpandEnv()

type Result

type Result struct {
	TestResults []TestResult
	Duration    time.Duration
	Failed      int
	Skipped     int
}

Result respresents the aggregation of all TestResults/summary of a runtime

type ResultStatus

type ResultStatus int

ResultStatus represents the status code of a test result

type Runner

type Runner struct {
	Nodes []Node
}

Runner holds the config and executes the desired runtime env

func (*Runner) Run

func (r *Runner) Run(tests []TestCase) <-chan TestResult

Run the runner

type Runtime

type Runtime struct {
	Runner       *Runner
	EventHandler *EventHandler
}

Runtime represents the current runtime, please use NewRuntime() instead of creating an instance directly

func NewRuntime

func NewRuntime(eh *EventHandler, nodes ...Node) Runtime

NewRuntime creates a new runtime and inits default nodes

func (*Runtime) Start

func (r *Runtime) Start(tests []TestCase) Result

Start starts the given test suite and executes all tests

type SSHExecutor

type SSHExecutor struct {
	Host         string
	User         string
	Password     string
	IdentityFile string
}

SSHExecutor

func (SSHExecutor) Execute

func (e SSHExecutor) Execute(test TestCase) TestResult

Execute executes a command on a remote host viá SSH

type TestCase

type TestCase struct {
	Title    string
	Command  CommandUnderTest
	Expected Expected
	Result   CommandResult
	Nodes    []string
	FileName string
	Skip     bool
}

TestCase represents a test case which will be executed by the runtime

type TestResult

type TestResult struct {
	TestCase         TestCase
	ValidationResult ValidationResult
	FailedProperty   string
	Tries            int
	Node             string
	Skipped          bool
}

TestResult represents the TestCase and the ValidationResult

func Validate

func Validate(test TestCase) TestResult

Validate validates the test results with the expected values The test should hold the result and expected to validate the result

type ValidationResult

type ValidationResult struct {
	Success bool
	Diff    string
}

ValidationResult will be returned after the validation was executed

Jump to

Keyboard shortcuts

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