Documentation
¶
Index ¶
- Constants
- Variables
- func CommonObjectMeta(ns string) metav1.ObjectMeta
- type ControlPlaneRefRequiredT
- type EmptyControlPlaneRefAllowedT
- type EventuallyConfig
- type ObjectWithControlPlaneRef
- type Scope
- type SupportedByKicT
- type TestCase
- type TestCasesGroup
- func NewCRDValidationTestCasesGroupCPRefChange[T ObjectWithControlPlaneRef[T]](t *testing.T, cfg *rest.Config, obj T, supportedByKIC SupportedByKicT, ...) TestCasesGroup[T]
- func NewCRDValidationTestCasesGroupCPRefChangeKICUnsupportedTypes[T ObjectWithControlPlaneRef[T]](t *testing.T, obj T, emptyControlPlaneRefAllowed EmptyControlPlaneRefAllowedT) TestCasesGroup[T]
- type WarningCollector
Constants ¶
const ( // DefaultEventuallyTimeout is the default timeout for EventuallyConfig. DefaultEventuallyTimeout = 3 * time.Second // DefaultEventuallyPeriod is the default period for EventuallyConfig. DefaultEventuallyPeriod = 10 * time.Millisecond )
Variables ¶
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 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) // 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.
type TestCasesGroup ¶
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 ¶
RunWithConfig runs all test cases in the group against the provided rest.Config's cluster.
type WarningCollector ¶
WarningCollector implements the rest.WarningHandler interface.
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.