test

package
v0.0.0-...-944484c Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 52 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(namespace string, timeout int, assertFiles ...string) error

Assert checks all provided assert files against a namespace. Upon assert failure, it prints the failures and returns an error

func Client

func Client(_ bool) (client.Client, error)

func DiscoveryClient

func DiscoveryClient() (discovery.DiscoveryInterface, error)

func Errors

func Errors(namespace string, timeout int, errorFiles ...string) error

Errors checks all provided errors files against a namespace. Upon assert failure, it prints the failures and returns an error

func IsMinVersion

func IsMinVersion(ver string) bool

IsMinVersion checks if pass ver is the min required kind version

func ObjectsFromPath

func ObjectsFromPath(path, dir string) ([]client.Object, error)

ObjectsFromPath returns an array of runtime.Objects for files / urls provided

func SetFlags

func SetFlags(flags *pflag.FlagSet)

Types

type Case

type Case struct {
	Steps              []*Step
	Name               string
	Dir                string
	SkipDelete         bool
	Timeout            int
	PreferredNamespace string
	RunLabels          labels.Set

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

	Logger testutils.Logger
	// Suppress is used to suppress logs
	Suppress []string
}

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(test *testing.T, cl client.Client, ns *namespace) error

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

func (*Case) DeleteNamespace

func (t *Case) DeleteNamespace(cl client.Client, ns *namespace) 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) NamespaceExists

func (t *Case) NamespaceExists(namespace string) (bool, error)

NamespaceExists gets namespace and returns true if it exists

func (*Case) Run

func (t *Case) Run(test *testing.T, ts *report.Testsuite)

Run runs a test case including all of its steps.

type Harness

type Harness struct {
	TestSuite harness.TestSuite
	T         *testing.T

	RunLabels labels.Set
	// 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. As a side effect, on first successful call this method also writes a kubernetes client config file in YAML format to a file called "kubeconfig" in the current directory.

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) Report

func (h *Harness) Report()

Report defines the report phase of the kuttl tests. If report format is nil it is skipped. otherwise it will provide a json or xml format report of tests in a junit format.

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

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
	SkipDelete bool

	Dir           string
	TestRunLabels labels.Set

	Step   *harness.TestStep
	Assert *harness.TestAssert

	Asserts []client.Object
	Apply   []client.Object
	Errors  []client.Object

	Timeout int

	Kubeconfig        string
	KubeconfigLoading string
	Context           string

	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, timeout int) []error

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

func (*Step) CheckAssertCommands

func (s *Step) CheckAssertCommands(ctx context.Context, namespace string, commands []harness.TestAssertCommand, timeout int) []error

CheckAssertCommands Runs the commands provided in `commands` and check if have been run successfully. the errors returned can be a a failure of executing the command or the failure of the command executed.

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(test *testing.T, 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

LoadYAML 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(test *testing.T, 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