test

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2020 License: Apache-2.0 Imports: 44 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetFlags added in v0.3.0

func SetFlags(flags *pflag.FlagSet)

Types

type Case

type Case struct {
	Steps      []*Step
	Name       string
	Dir        string
	SkipDelete bool
	Timeout    int

	Client          func(forceNew bool) (client.Client, error)
	DiscoveryClient func() (discovery.DiscoveryInterface, error)

	Logger testutils.Logger
}

Case contains all of the test steps and the Kubernetes client and other global configuration for a test.

func (*Case) CollectEvents

func (t *Case) CollectEvents(namespace string)

CollectEvents gathers all events from namespace and prints it out to log

func (*Case) CollectTestStepFiles

func (t *Case) CollectTestStepFiles() (map[int64][]string, error)

CollectTestStepFiles collects a map of test steps and their associated files from a directory.

func (*Case) CreateNamespace

func (t *Case) CreateNamespace(namespace string) error

CreateNamespace creates a namespace in Kubernetes to use for a test.

func (*Case) DeleteNamespace

func (t *Case) DeleteNamespace(namespace string) error

DeleteNamespace deletes a namespace in Kubernetes after we are done using it.

func (*Case) LoadTestSteps

func (t *Case) LoadTestSteps() error

LoadTestSteps loads all of the test steps for a test case.

func (*Case) Run

func (t *Case) Run(test *testing.T)

Run runs a test case including all of its steps.

type Harness

type Harness struct {
	TestSuite harness.TestSuite
	T         *testing.T
	// contains filtered or unexported fields
}

Harness loads and runs tests based on the configuration provided.

func (*Harness) Client

func (h *Harness) Client(forceNew bool) (client.Client, error)

Client returns the current Kubernetes client for the test harness.

func (*Harness) Config

func (h *Harness) Config() (*rest.Config, error)

Config returns the current Kubernetes configuration - either from the environment or from the created temporary control plane.

func (*Harness) DiscoveryClient

func (h *Harness) DiscoveryClient() (discovery.DiscoveryInterface, error)

DiscoveryClient returns the current Kubernetes discovery client for the test harness.

func (*Harness) DockerClient

func (h *Harness) DockerClient() (testutils.DockerClient, error)

DockerClient returns the Docker client to use for the test harness.

func (*Harness) GetLogger

func (h *Harness) GetLogger() testutils.Logger

GetLogger returns an initialized test logger.

func (*Harness) GetTimeout

func (h *Harness) GetTimeout() int

GetTimeout returns the configured timeout for the test suite.

func (*Harness) LoadTests

func (h *Harness) LoadTests(dir string) ([]*Case, error)

LoadTests loads all of the tests in a given directory.

func (*Harness) Run

func (h *Harness) Run()

Run the test harness - start the control plane and then run the tests.

func (*Harness) RunKIND

func (h *Harness) RunKIND() (*rest.Config, error)

RunKIND starts a KIND cluster.

func (*Harness) RunTestEnv

func (h *Harness) RunTestEnv() (*rest.Config, error)

RunTestEnv starts a Kubernetes API server and etcd server for use in the tests and returns the Kubernetes configuration.

func (*Harness) RunTests

func (h *Harness) RunTests()

RunTests should be called from within a Go test (t) and launches all of the KUTTL integration tests at dir.

func (*Harness) Setup added in v0.1.0

func (h *Harness) Setup()

Setup spins up the test env based on configuration It can be used to start env which can than be modified prior to running tests, otherwise use Run().

func (*Harness) Stop

func (h *Harness) Stop()

Stop the test environment and clean up the harness.

type Step

type Step struct {
	Name  string
	Index int

	Dir string

	Step   *harness.TestStep
	Assert *harness.TestAssert

	Asserts []runtime.Object
	Apply   []runtime.Object
	Errors  []runtime.Object

	Timeout int

	Client          func(forceNew bool) (client.Client, error)
	DiscoveryClient func() (discovery.DiscoveryInterface, error)

	Logger testutils.Logger
}

A Step contains the name of the test step, its index in the test, and all of the test step's settings (including objects to apply and assert on).

func (*Step) Check

func (s *Step) Check(namespace string) []error

Check checks if the resources defined in Asserts and Errors are in the correct state.

func (*Step) CheckResource

func (s *Step) CheckResource(expected runtime.Object, namespace string) []error

CheckResource checks if the expected resource's state in Kubernetes is correct.

func (*Step) CheckResourceAbsent

func (s *Step) CheckResourceAbsent(expected runtime.Object, namespace string) error

CheckResourceAbsent checks if the expected resource's state is absent in Kubernetes.

func (*Step) Clean

func (s *Step) Clean(namespace string) error

Clean deletes all resources defined in the Apply list.

func (*Step) Create

func (s *Step) Create(namespace string) []error

Create applies all resources defined in the Apply list.

func (*Step) DeleteExisting

func (s *Step) DeleteExisting(namespace string) error

DeleteExisting deletes any resources in the TestStep.Delete list prior to running the tests.

func (*Step) GetTimeout

func (s *Step) GetTimeout() int

GetTimeout gets the timeout defined for the test step.

func (*Step) LoadYAML

func (s *Step) LoadYAML(file string) error

LoadYAMLFromFile loads the resources from a YAML file for a test step:

  • If the YAML file is called "assert", then it contains objects to add to the test step's list of assertions.
  • If the YAML file is called "errors", then it contains objects that, if seen, mark a test immediately failed.
  • All other YAML files are considered resources to create.

func (*Step) Run

func (s *Step) Run(namespace string) []error

Run runs a KUTTL test step: 1. Apply all desired objects to Kubernetes. 2. Wait for all of the states defined in the test step's asserts to be true.'

func (*Step) String

func (s *Step) String() string

String implements the string interface, returning the name of the test step.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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