envtest

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrBodyDataConstraintError is a JSON error response body for a data constraint error.
	ErrBodyDataConstraintError = `` /* 291-byte string literal not displayed */

)

Variables

This section is empty.

Functions

func Context

Context creates a context for tests with deadline if it was provided. It also cancels the context on test cleanup.

func DumpLogsIfTestFailed

func DumpLogsIfTestFailed(t *testing.T, logs LogsObserver)

DumpLogsIfTestFailed dumps the provided logs the if the test failed.

func NameFromT

func NameFromT(t *testing.T) string

NameFromT returns a name suitable for use in Kubernetes resources for a given test. This is used e.g. when setting kong addon's name.

func NewControllerClient

func NewControllerClient(t *testing.T, scheme *runtime.Scheme, cfg *rest.Config) ctrlclient.Client

NewControllerClient returns a new controller-runtime Client for provided runtime.Scheme and rest.Config.

func Setup

func Setup(t *testing.T, ctx context.Context, scheme *k8sruntime.Scheme) (*rest.Config, *corev1.Namespace)

Setup sets up a test k8s API server environment and returned the configuration.

func StartReconcilers

func StartReconcilers(
	ctx context.Context,
	t *testing.T,
	mgr manager.Manager,
	logs LogsObserver,
	reconcilers ...Reconciler,
)

StartReconcilers creates a controller manager and starts the provided reconciler as its runnable. It also adds a t.Cleanup which waits for the manager to exit so that the test can be self contained and logs from different tests' managers don't mix up.

Types

type LogsObserver

type LogsObserver interface {
	// All returns all the logs that have been observed so far.
	All() []observer.LoggedEntry
}

LogsObserver is an interface for observing logs.

func CreateTestLogger

func CreateTestLogger(ctx context.Context) (context.Context, logr.Logger, LogsObserver)

CreateTestLogger creates a logger for use in tests. It returns the logger - which is also added to the context - and the observer which can be used to dump logs if the test fails.

func NewManager

func NewManager(t *testing.T, ctx context.Context, cfg *rest.Config, s *runtime.Scheme) (manager.Manager, LogsObserver)

NewManager returns a manager and a logs observer. The logs observer can be used to dump logs if the test fails. The returned manager can be used with StartReconcilers() to start a list of provided reconcilers with the manager.

type Reconciler

type Reconciler interface {
	SetupWithManager(context.Context, ctrl.Manager) error
}

Reconciler represents a reconciler.

Jump to

Keyboard shortcuts

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