common

package
v2.2.7 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// DefaultEventuallyTimeout is the default timeout for EventuallyConfig.
	DefaultEventuallyTimeout = 5 * time.Second
	// DefaultEventuallyPeriod is the default period for EventuallyConfig.
	DefaultEventuallyPeriod = 10 * time.Millisecond
)

Variables

View Source
var SharedEventuallyConfig = EventuallyConfig{
	Timeout: 15 * time.Second,
	Period:  100 * time.Millisecond,
}

SharedEventuallyConfig is the common Eventually configuration used across tests.

Functions

func CommonObjectMeta

func CommonObjectMeta(ns string) metav1.ObjectMeta

CommonObjectMeta returns a common ObjectMeta for test objects in the given namespace.

Types

type ControlPlaneRefRequiredT

type ControlPlaneRefRequiredT bool

ControlPlaneRefRequiredT is a type to specify whether control plane ref is required or not.

const (
	// ControlPlaneRefRequired represents that control plane ref is required.
	ControlPlaneRefRequired ControlPlaneRefRequiredT = true
	// ControlPlaneRefNotRequired represents that control plane ref is not required.
	ControlPlaneRefNotRequired ControlPlaneRefRequiredT = false
)

type EmptyControlPlaneRefAllowedT

type EmptyControlPlaneRefAllowedT bool

EmptyControlPlaneRefAllowedT is a type to specify whether an empty control plane ref is allowed or not.

const (
	// EmptyControlPlaneRefAllowed is a value to specify that an empty control plane ref is allowed.
	EmptyControlPlaneRefAllowed EmptyControlPlaneRefAllowedT = true
	// EmptyControlPlaneRefNotAllowed is a value to specify that an empty control plane ref is not allowed.
	EmptyControlPlaneRefNotAllowed EmptyControlPlaneRefAllowedT = false
)

type EventuallyConfig

type EventuallyConfig struct {
	// Timeout is the maximum time to wait for the condition to be true.
	Timeout time.Duration
	// Period is the time to wait between retries.
	Period time.Duration
}

EventuallyConfig is the configuration for assert.Eventually() which is used to assert errors.

type ObjectWithControlPlaneRef

type ObjectWithControlPlaneRef[T any] interface {
	client.Object
	DeepCopy() T
	SetConditions([]metav1.Condition)
	SetControlPlaneRef(*commonv1alpha1.ControlPlaneRef)
	GetControlPlaneRef() *commonv1alpha1.ControlPlaneRef
}

ObjectWithControlPlaneRef is an interface for objects that have a ControlPlaneRef and support deepcopy and condition setting.

type Scope

type Scope byte

Scope represents the scope of the object.

const (
	// ScopeCluster represents the cluster scope.
	ScopeCluster Scope = iota
	// ScopeNamespace represents the namespace scope.
	ScopeNamespace
)

type SupportedByKicT

type SupportedByKicT bool

SupportedByKicT is a type to specify whether an object is supported by KIC or not.

const (
	// SupportedByKIC represents that the object is supported by KIC.
	SupportedByKIC SupportedByKicT = true
	// NotSupportedByKIC represents that the object is not supported by KIC.
	NotSupportedByKIC SupportedByKicT = false
)

type TestCase

type TestCase[T client.Object] struct {
	// Name is the name of the test case.
	Name string

	// SkipReason is the reason to skip the test case.
	SkipReason string

	// TestObject is the object to be tested.
	TestObject T

	// ExpectedErrorMessage is the expected error message when creating the object.
	ExpectedErrorMessage *string

	// ExpectedErrorEventuallyConfig is the configuration for assert.Eventually() which is used to assert the create error.
	// If not provided the error is checked immediately, just once.
	ExpectedErrorEventuallyConfig EventuallyConfig

	// ExpectedUpdateErrorMessage is the expected error message when updating the object.
	ExpectedUpdateErrorMessage *string

	// ExpectedStatusUpdateErrorMessage is the expected error message when updating the object status.
	ExpectedStatusUpdateErrorMessage *string

	// Update is a function that updates the object in the test case after it's created.
	// It can be used to verify CEL rules that verify the previous object's version against the new one.
	Update func(T)

	// StatusUpdate is a function that updates the status of the object in the test case after it's created.
	StatusUpdate func(T)

	// WarningCollector (optional) collects API server warnings emitted during operations.
	// If set together with ExpectedWarningMessage, the test will assert that a warning containing the
	// expected message substring was produced.
	WarningCollector *WarningCollector

	// ExpectedWarningMessage is the substring expected to be found in at least one collected warning.
	ExpectedWarningMessage *string

	// Assert is an optional function to perform additional assertions on the created object.
	// It is called after the object is created and before an update (if specified).
	Assert func(*testing.T, T)
}

TestCase represents a test case for CRD validation.

func (*TestCase[T]) Run

func (tc *TestCase[T]) Run(t *testing.T)

Run runs the test case.

func (*TestCase[T]) RunWithConfig

func (tc *TestCase[T]) RunWithConfig(t *testing.T, cfg *rest.Config, scheme *runtime.Scheme)

RunWithConfig runs the test case against the provided rest.Config's cluster.

type TestCasesGroup

type TestCasesGroup[T client.Object] []TestCase[T]

TestCasesGroup is a group of test cases related to CRD validation.

func NewCRDValidationTestCasesGroupCPRefChange

func NewCRDValidationTestCasesGroupCPRefChange[
	T ObjectWithControlPlaneRef[T],
](
	t *testing.T,
	cfg *rest.Config,
	obj T,
	supportedByKIC SupportedByKicT,
	controlPlaneRefRequired ControlPlaneRefRequiredT,
) TestCasesGroup[T]

NewCRDValidationTestCasesGroupCPRefChange creates a test cases group for control plane ref change.

func NewCRDValidationTestCasesGroupCPRefChangeKICUnsupportedTypes

func NewCRDValidationTestCasesGroupCPRefChangeKICUnsupportedTypes[
	T ObjectWithControlPlaneRef[T],
](
	t *testing.T,
	obj T,
	emptyControlPlaneRefAllowed EmptyControlPlaneRefAllowedT,
) TestCasesGroup[T]

NewCRDValidationTestCasesGroupCPRefChangeKICUnsupportedTypes returns a group of test cases for testing control plane ref change to KIC unsupported types.

func (TestCasesGroup[T]) Run

func (g TestCasesGroup[T]) Run(t *testing.T)

Run runs all test cases in the group.

func (TestCasesGroup[T]) RunWithConfig

func (g TestCasesGroup[T]) RunWithConfig(t *testing.T, cfg *rest.Config, scheme *runtime.Scheme)

RunWithConfig runs all test cases in the group against the provided rest.Config's cluster.

type WarningCollector

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

WarningCollector implements the rest.WarningHandler interface. It's safe for concurrent use.

func (*WarningCollector) GetWarnings

func (wc *WarningCollector) GetWarnings() []string

GetWarnings returns the collected warnings.

func (*WarningCollector) HandleWarningHeader

func (wc *WarningCollector) HandleWarningHeader(_ int, _ string, warning string)

HandleWarningHeader implements the rest.WarningHandler interface.

Jump to

Keyboard shortcuts

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