test

package
v3.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEventuallyTimeout = errors.New("timed out waiting for condition")

Functions

func AssertErrorCondition

func AssertErrorCondition[T any](t *testing.T, o client.Object, getConditions func(T) []metav1.Condition, expectedReason string)

func AssertHasPhase

func AssertHasPhase(t *testing.T, o object.MultiPhaseObject, phase string)

func AssertIsOnError

func AssertIsOnError(t *testing.T, o object.RemoteObject, expected bool)

func AssertIsSync

func AssertIsSync(t *testing.T, o object.RemoteObject)

func AssertManagedByOperator

func AssertManagedByOperator(t *testing.T, obj client.Object)

func AssertOwnerReference

func AssertOwnerReference(t *testing.T, obj client.Object, owner metav1.Object)

func AssertReadyCondition

func AssertReadyCondition[T any](t *testing.T, o client.Object, getConditions func(T) []metav1.Condition)

func EqualFromYamlFile

func EqualFromYamlFile[k8sobject any](t *testing.T, expectedYamlFile string, actual client.Object, s runtime.ObjectTyper)

func RunWithTimeout

func RunWithTimeout(f func() error, timeout time.Duration, interval time.Duration) (isTimeout bool, err error)

func WaitForGenerationIncrement

func WaitForGenerationIncrement[T client.Object](t *testing.T, c client.Client, key types.NamespacedName, minGeneration int64, timeout time.Duration)

func WaitForReadyCondition

func WaitForReadyCondition[T client.Object](t *testing.T, c client.Client, key types.NamespacedName, timeout time.Duration)

func WaitForResourceVersionChange

func WaitForResourceVersionChange[T client.Object](t *testing.T, c client.Client, key types.NamespacedName, oldVersion string, timeout time.Duration)

Types

type CRBuilder

type CRBuilder[T client.Object] struct {
	// contains filtered or unexported fields
}

func NewCR

func NewCR[T client.Object](name, namespace string) *CRBuilder[T]

func (*CRBuilder[T]) Build

func (b *CRBuilder[T]) Build() T

func (*CRBuilder[T]) WithAnnotations

func (b *CRBuilder[T]) WithAnnotations(annotations map[string]string) *CRBuilder[T]

func (*CRBuilder[T]) WithLabels

func (b *CRBuilder[T]) WithLabels(labels map[string]string) *CRBuilder[T]

func (*CRBuilder[T]) WithTypeMeta

func (b *CRBuilder[T]) WithTypeMeta(gvk schema.GroupVersionKind) *CRBuilder[T]

type ControllerSetupFunc

type ControllerSetupFunc func(mgr ctrl.Manager, k8sClient client.Client, cfg *rest.Config)

type EnvTestSuite

type EnvTestSuite struct {
	suite.Suite
	K8sClient client.Client
	Cfg       *rest.Config
	Manager   ctrl.Manager

	Config EnvTestSuiteConfig
	// contains filtered or unexported fields
}

func (*EnvTestSuite) SetupSuite

func (s *EnvTestSuite) SetupSuite()

func (*EnvTestSuite) TearDownSuite

func (s *EnvTestSuite) TearDownSuite()

type EnvTestSuiteConfig

type EnvTestSuiteConfig struct {
	CRDDirectoryPaths     []string
	SchemeRegistrations   []SchemeRegistration
	ControllerSetupFuncs  []ControllerSetupFunc
	MetricsBindAddress    string
	ErrorIfCRDPathMissing bool
}

type InterceptorClient

type InterceptorClient struct {
	client.Client

	GetInterceptor          func(ctx context.Context, key types.NamespacedName, obj client.Object, opts ...client.GetOption) error
	ListInterceptor         func(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
	CreateInterceptor       func(ctx context.Context, obj client.Object, opts ...client.CreateOption) error
	DeleteInterceptor       func(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error
	UpdateInterceptor       func(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error
	PatchInterceptor        func(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error
	DeleteAllOfInterceptor  func(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error
	StatusUpdateInterceptor func(ctx context.Context, obj client.Object, opts ...client.SubResourceUpdateOption) error
	StatusPatchInterceptor  func(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.SubResourcePatchOption) error
	StatusCreateInterceptor func(ctx context.Context, obj client.Object, subResource client.Object, opts ...client.SubResourceCreateOption) error
}

func NewInterceptorClient

func NewInterceptorClient(c client.Client) *InterceptorClient

func (*InterceptorClient) Create

func (c *InterceptorClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error

func (*InterceptorClient) Delete

func (c *InterceptorClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error

func (*InterceptorClient) DeleteAllOf

func (c *InterceptorClient) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error

func (*InterceptorClient) Get

func (*InterceptorClient) GroupVersionKindFor

func (c *InterceptorClient) GroupVersionKindFor(obj runtime.Object) (schema.GroupVersionKind, error)

func (*InterceptorClient) IsObjectNamespaced

func (c *InterceptorClient) IsObjectNamespaced(obj runtime.Object) (bool, error)

func (*InterceptorClient) List

func (*InterceptorClient) Patch

func (c *InterceptorClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error

func (*InterceptorClient) RESTMapper

func (c *InterceptorClient) RESTMapper() meta.RESTMapper

func (*InterceptorClient) Scheme

func (c *InterceptorClient) Scheme() *runtime.Scheme

func (*InterceptorClient) Status

func (*InterceptorClient) SubResource

func (c *InterceptorClient) SubResource(subResource string) client.SubResourceClient

func (*InterceptorClient) Update

func (c *InterceptorClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error

type InterceptorStatusClient

type InterceptorStatusClient struct {
	// contains filtered or unexported fields
}

func (*InterceptorStatusClient) Create

func (*InterceptorStatusClient) Patch

func (*InterceptorStatusClient) Update

type SchemeRegistration

type SchemeRegistration func(scheme *runtime.Scheme)

type TestCase

type TestCase[k8sObject client.Object] struct {
	// Permit to lauch some preaction, like init mock
	PreTest func(stepName *string, data map[string]any) error
	Steps   []TestStep[k8sObject]
	// contains filtered or unexported fields
}

func NewTestCase

func NewTestCase[k8sObject client.Object](t *testing.T, c client.Client, key types.NamespacedName, wait time.Duration, data map[string]any) *TestCase[k8sObject]

func (*TestCase[k8sObject]) Eventually

func (h *TestCase[k8sObject]) Eventually(fn func(c client.Client) error, timeout, interval time.Duration) error

func (*TestCase[k8sObject]) Run

func (h *TestCase[k8sObject]) Run()

type TestStep

type TestStep[k8sObject client.Object] struct {
	Name  string
	Pre   func(c client.Client, data map[string]any) error
	Do    func(c client.Client, key types.NamespacedName, o k8sObject, data map[string]any) error
	Check func(t *testing.T, c client.Client, key types.NamespacedName, o k8sObject, data map[string]any) error
}

func NewCreateStep

func NewCreateStep[T client.Object](builder func(c client.Client, key types.NamespacedName) (T, error)) TestStep[T]

func NewDeleteStep

func NewDeleteStep[T client.Object]() TestStep[T]

Jump to

Keyboard shortcuts

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