Documentation
¶
Index ¶
Constants ¶
const ( // DefaultsKey is the key within the Defaults collection for // scenario defaults. Note that this isn't exposed in the YAML schema for a // scenario. It's just used as a way of indicating to the scenario runner // what was found in the scenario YAML's `defaults` top-level field. DefaultsKey = "gdt.scenario" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Defaults ¶
type Defaults struct {
// Timeout has fields that represent the default timeout behaviour and
// expectations to use for test specs in the scenario.
Timeout *gdttypes.Timeout `yaml:"timeout,omitempty"`
// Retry has fields that represent the default retry behaviour for test
// specs in the scenario.
Retry *gdttypes.Retry `yaml:"retry,omitempty"`
}
Defaults is the scenario's defaults collection
type Scenario ¶
type Scenario struct {
// Path is the filepath to the test case.
Path string `yaml:"-"`
// Name is the short name for the test case. If empty, defaults to the base
// filename in Path.
Name string `yaml:"name,omitempty"`
// Description is a description of the tests contained in the test case.
Description string `yaml:"description,omitempty"`
// Defaults contains any default configuration values for test specs
// contained within the test scenario.
//
// During parsing, plugins are handed this raw data and asked to interpret
// it into known configuration values for that plugin.
Defaults map[string]interface{} `yaml:"defaults,omitempty"`
// Fixtures specifies an ordered list of fixtures the test case depends on.
Fixtures []string `yaml:"fixtures,omitempty"`
// SkipIf contains a list of evaluable conditions. If any of the conditions
// evaluates successfully, the test scenario will be skipped. This allows
// test authors to specify "pre-flight checks" that should pass before
// attempting any of the actions in the scenario's tests.
//
// For example, let's assume you have a `gdt-kube` scenario that looks like
// this:
//
// “`yaml
// tests:
// - kube.create: manifests/nginx-deployment.yaml
// - kube:
// get: deployments/nginx
// assert:
// matches:
// status:
// readyReplicas: 2
// - kube.delete: deployments/nginx
// “`
//
// If you execute the above test and there is already an 'nginx'
// deployment, the `kube.create` test will fail. To prevent the scenario
// from proceeding with the tests if an 'nginx' deployment already exists,
// you could add the following
//
// “`yaml
// skip-if:
// - kube.get: deployments/nginx
// tests:
// - kube.create: manifests/nginx-deployment.yaml
// - kube:
// get: deployments/nginx
// assert:
// matches:
// status:
// readyReplicas: 2
// - kube.delete: deployments/nginx
// “`
//
// With the above, if an 'nginx' deployment exists already, the scenario
// will skip all the tests.
SkipIf []gdttypes.Evaluable `yaml:"skip-if,omitempty"`
// Tests is the collection of test units in this test case. These will be
// the fully parsed and materialized plugin Spec structs.
Tests []gdttypes.Evaluable `yaml:"tests,omitempty"`
// contains filtered or unexported fields
}
Scenario is a generalized gdt test case file. It contains a set of Runnable test units.
func FromBytes ¶
func FromBytes( contents []byte, mods ...ScenarioModifier, ) (*Scenario, error)
FromBytes returns a Scenario after parsing the supplied contents
func FromReader ¶
func FromReader( r io.Reader, mods ...ScenarioModifier, ) (*Scenario, error)
FromReader parses the supplied io.Reader and returns a Scenario representing the contents in the reader. Returns an error if any syntax or validation failed
func (*Scenario) Run ¶
Run executes the scenario. The error that is returned will always be derived from `gdterrors.RuntimeError` and represents an *unrecoverable* error.
Test assertion failures are *not* considered errors. The Scenario.Run() method controls whether `testing.T.Fail()` or `testing.T.Skip()` is called which will mark the test units failed or skipped if a test unit evaluates to false.
type ScenarioModifier ¶
type ScenarioModifier func(s *Scenario)
ScenarioModifier sets some value on the test scenario
func WithDefaults ¶
func WithDefaults(defaults map[string]interface{}) ScenarioModifier
WithDefaults sets a test scenario's Defaults attribute
func WithDescription ¶
func WithDescription(description string) ScenarioModifier
WithDescription sets a test scenario's Description attribute
func WithName ¶
func WithName(name string) ScenarioModifier
WithName sets a test scenario's Name attribute
func WithPath ¶
func WithPath(path string) ScenarioModifier
WithPath sets a test scenario's Path attribute
func WithRequires ¶
func WithRequires(fixtures []string) ScenarioModifier
WithFixtures sets a test scenario's Fixtures attribute