common

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var CommonObjectMeta = metav1.ObjectMeta{
	GenerateName: "test-",
	Namespace:    "default",
}

CommonObjectMeta is a common object meta used in tests.

Functions

This section is empty.

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 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

	// 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)
}

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 interface {
		client.Object
		DeepCopy() T
		SetConditions([]metav1.Condition)
		SetControlPlaneRef(*commonv1alpha1.ControlPlaneRef)
		GetControlPlaneRef() *commonv1alpha1.ControlPlaneRef
	},
](
	t *testing.T,
	obj T,
	supportedByKIC SupportedByKicT,
	controlPlaneRefRequired ControlPlaneRefRequiredT,
) TestCasesGroup[T]

NewCRDValidationTestCasesGroupCPRefChange creates a test cases group for control plane ref change

func NewCRDValidationTestCasesGroupCPRefChangeKICUnsupportedTypes

func NewCRDValidationTestCasesGroupCPRefChangeKICUnsupportedTypes[
	T interface {
		client.Object
		DeepCopy() T
		SetConditions([]metav1.Condition)
		SetControlPlaneRef(*commonv1alpha1.ControlPlaneRef)
		GetControlPlaneRef() *commonv1alpha1.ControlPlaneRef
	},
](
	t *testing.T,
	obj T,
	emptyControlPlaneRefAllowed EmptyControlPlaneRefAllowedT,
) TestCasesGroup[T]

NewCRDValidationTestCasesGroupCPRefChangeKICUnsupportedTypes returns a test cases group 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.

Jump to

Keyboard shortcuts

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