Documentation
¶
Overview ¶
Package testutil provides shared test helpers for controller tests.
Index ¶
- Constants
- func CRDDirPath() string
- func CollectEvents(ch chan string) []string
- func DrainEvents(ch chan string)
- func GetFirstFoundEnvTestBinaryDir() string
- func Request(name string) ctrl.Request
- func RequireCondition(t *testing.T, conditions []metav1.Condition, condType string, ...)
- func RequireConditions(t *testing.T, actual []metav1.Condition, expected []ConditionExpect)
- func RequireEvents(t *testing.T, ch chan string, wantEvents []string)
- func Scheme(t *testing.T, adders ...func(*runtime.Scheme) error) *runtime.Scheme
- type ConditionExpect
Constants ¶
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 ¶
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 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 ¶
RequireEvents asserts that the collected events from ch exactly match wantEvents (order-independent). If wantEvents is nil the check is skipped.
Types ¶
type ConditionExpect ¶
type ConditionExpect struct {
Type string
Status metav1.ConditionStatus
Reason string
}
ConditionExpect describes an expected condition for declarative assertions.