Documentation
¶
Index ¶
- Constants
- Variables
- type ControlPlaneRefRequiredT
- type EmptyControlPlaneRefAllowedT
- type EventuallyConfig
- type Scope
- type SupportedByKicT
- type TestCase
- type TestCasesGroup
- func NewCRDValidationTestCasesGroupCPRefChange[T interface{ ... }](t *testing.T, obj T, supportedByKIC SupportedByKicT, ...) TestCasesGroup[T]
- func NewCRDValidationTestCasesGroupCPRefChangeKICUnsupportedTypes[T interface{ ... }](t *testing.T, obj T, emptyControlPlaneRefAllowed EmptyControlPlaneRefAllowedT) TestCasesGroup[T]
- type WarningCollector
Constants ¶
const ( // DefaultEventuallyTimeout is the default timeout for EventuallyConfig. DefaultEventuallyTimeout = 1 * time.Second // DefaultEventuallyPeriod is the default period for EventuallyConfig. DefaultEventuallyPeriod = 10 * time.Millisecond )
Variables ¶
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 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 }
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 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 ¶
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 k8s client-go rest.WarningHandler interface and collects warning messages emitted by the API server.
It is used in envtest-based CRD validation tests to assert that specific warnings were produced when creating or updating objects.
The interface method signature is:
HandleWarningHeader(code int, agent, message string)
We only need to collect the message content for assertions.
Note: this lives in a test-only helper package, so thread-safety is kept simple with a mutex and a slice copy on read.
func (*WarningCollector) HandleWarningHeader ¶
func (w *WarningCollector) HandleWarningHeader(_ int, _ string, message string)
HandleWarningHeader records a warning message.
func (*WarningCollector) Messages ¶
func (w *WarningCollector) Messages() []string
Messages returns a snapshot copy of collected warning messages.