testutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package testutil provides shared test helpers for controller tests.

Index

Constants

View Source
const (
	// TestNamespace is the namespace used in tests.
	TestNamespace = "default"
	// TestNodeName is the node name used in tests.
	TestNodeName = "test-node"
)

Variables

This section is empty.

Functions

func CRDDirPath

func CRDDirPath() string

CRDDirPath returns the CRD directory path relative to an instance controller package (controllers/instance/X/).

func CollectEvents

func CollectEvents(ch chan string) []string

CollectEvents drains all currently buffered events from the FakeRecorder channel and returns them. It reads until the channel is empty (non-blocking).

func DrainEvents

func DrainEvents(ch chan string)

DrainEvents discards all currently buffered events from the FakeRecorder channel.

func GetFirstFoundEnvTestBinaryDir

func GetFirstFoundEnvTestBinaryDir() string

GetFirstFoundEnvTestBinaryDir returns the first found envtest binary directory, or empty string if not found.

func Request

func Request(name string) ctrl.Request

Request creates a ctrl.Request for the given resource name in TestNamespace.

func RequireCondition

func RequireCondition(t *testing.T, conditions []metav1.Condition, condType string, status metav1.ConditionStatus, reason string)

RequireCondition finds a condition by type and asserts its status and reason.

func RequireConditions

func RequireConditions(t *testing.T, actual []metav1.Condition, expected []ConditionExpect)

RequireConditions asserts that the given conditions match all expectations (count + each entry).

func RequireEvents

func RequireEvents(t *testing.T, ch chan string, wantEvents []string)

RequireEvents asserts that the collected events from ch exactly match wantEvents (order-independent). If wantEvents is nil the check is skipped.

func Scheme

func Scheme(t *testing.T, adders ...func(*runtime.Scheme) error) *runtime.Scheme

Scheme creates a runtime.Scheme with common K8s types (core, apps, rbac) and any additional types registered via the provided adders.

Types

type ConditionExpect

type ConditionExpect struct {
	Type   string
	Status metav1.ConditionStatus
	Reason string
}

ConditionExpect describes an expected condition for declarative assertions.

Jump to

Keyboard shortcuts

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