envtest

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2021 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Overview

Package envtest contains the test environment to run integration tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run added in v0.4.1

func Run(ctx context.Context, input RunInput) int

Run executes the tests of the given testing.M in a test environment. Note: The environment will be created in this func and should not be created before. This func takes a *Environment

because our tests require access to the *Environment. We use this field to make the created Environment available
to the consumer.

Note: Test environment creation can be skipped by setting the environment variable `CAPI_DISABLE_TEST_ENV`. This only

makes sense when executing tests which don't require the test environment, e.g. tests using only the fake client.

Types

type Environment

type Environment struct {
	manager.Manager
	client.Client
	Config *rest.Config
	// contains filtered or unexported fields
}

Environment encapsulates a Kubernetes local test environment.

func (*Environment) Cleanup

func (e *Environment) Cleanup(ctx context.Context, objs ...client.Object) error

Cleanup deletes all the given objects.

func (*Environment) CleanupAndWait

func (e *Environment) CleanupAndWait(ctx context.Context, objs ...client.Object) error

CleanupAndWait deletes all the given objects and waits for the cache to be updated accordingly.

NOTE: Waiting for the cache to be updated helps in preventing test flakes due to the cache sync delays.

func (*Environment) CreateAndWait

func (e *Environment) CreateAndWait(ctx context.Context, obj client.Object, opts ...client.CreateOption) error

CreateAndWait creates the given object and waits for the cache to be updated accordingly.

NOTE: Waiting for the cache to be updated helps in preventing test flakes due to the cache sync delays.

func (*Environment) CreateKubeconfigSecret

func (e *Environment) CreateKubeconfigSecret(ctx context.Context, cluster *clusterv1.Cluster) error

CreateKubeconfigSecret generates a new Kubeconfig secret from the envtest config.

func (*Environment) CreateNamespace

func (e *Environment) CreateNamespace(ctx context.Context, generateName string) (*corev1.Namespace, error)

CreateNamespace creates a new namespace with a generated name.

func (*Environment) WaitForWebhooks

func (e *Environment) WaitForWebhooks()

WaitForWebhooks waits for the webhook server to be available.

type RunInput added in v0.4.1

type RunInput struct {
	M                   *testing.M
	ManagerUncachedObjs []client.Object
	SetupIndexes        func(ctx context.Context, mgr ctrl.Manager)
	SetupReconcilers    func(ctx context.Context, mgr ctrl.Manager)
	SetupEnv            func(e *Environment)
}

RunInput is the input for Run.

Jump to

Keyboard shortcuts

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