Documentation
¶
Overview ¶
Package framework provides shared infrastructure for E2E tests.
Index ¶
- Constants
- Variables
- func CreateTestNamespace(ctx context.Context, c client.Client, prefix string) string
- func DeleteClusterTestApp(ctx context.Context, c client.Client, name string)
- func GetClusterCondition(ctx context.Context, c client.Client, name string, conditionType string) func(gomega.Gomega) *metav1.Condition
- func GetCondition(ctx context.Context, c client.Client, key types.NamespacedName, ...) func(gomega.Gomega) *metav1.Condition
- func HaveConditionStatus(status metav1.ConditionStatus, reason string) gomegatypes.GomegaMatcher
- func InstallCRDs(cfg *rest.Config) error
- type ClusterComponentFactory
- type ClusterE2EReconciler
- func (r *ClusterE2EReconciler) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error)
- func (r *ClusterE2EReconciler) RegisterComponent(name string, factory ClusterComponentFactory)
- func (r *ClusterE2EReconciler) RegisterResource(name string, factory ClusterResourceFactory)
- func (r *ClusterE2EReconciler) Unregister(name string)
- type ClusterResourceFactory
- type ClusterTestApp
- type ClusterTestAppList
- type ComponentFactory
- type E2EReconciler
- func (r *E2EReconciler) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error)
- func (r *E2EReconciler) RegisterComponent(key types.NamespacedName, factory ComponentFactory)
- func (r *E2EReconciler) RegisterResource(key types.NamespacedName, factory ResourceFactory)
- func (r *E2EReconciler) Unregister(key types.NamespacedName)
- type ResourceFactory
- type TestApp
- type TestAppList
- type TestAppSpec
- type TestAppStatus
Constants ¶
const DefaultPolling = 2 * time.Second
DefaultPolling is the default polling interval for Eventually assertions.
const DefaultTimeout = 120 * time.Second
DefaultTimeout is the default timeout for Eventually assertions in E2E tests.
Variables ¶
var ( // GroupVersion is the group version used to register the TestApp types. GroupVersion = schema.GroupVersion{Group: "e2e.ocf.io", Version: "v1alpha1"} // SchemeBuilder is used to add Go types to the GroupVersionKind scheme. SchemeBuilder = runtime.NewSchemeBuilder(func(scheme *runtime.Scheme) error { scheme.AddKnownTypes(GroupVersion, &TestApp{}, &TestAppList{}, &ClusterTestApp{}, &ClusterTestAppList{}, ) metav1.AddToGroupVersion(scheme, GroupVersion) return nil }) // AddToScheme adds the E2E types to the given scheme. AddToScheme = SchemeBuilder.AddToScheme // TestAppCRD is the programmatic CRD definition for the namespace-scoped TestApp. TestAppCRD = &apiextensionsv1.CustomResourceDefinition{ ObjectMeta: metav1.ObjectMeta{ Name: "testapps.e2e.ocf.io", }, Spec: apiextensionsv1.CustomResourceDefinitionSpec{ Group: "e2e.ocf.io", Names: apiextensionsv1.CustomResourceDefinitionNames{ Kind: "TestApp", ListKind: "TestAppList", Plural: "testapps", Singular: "testapp", }, Scope: apiextensionsv1.NamespaceScoped, Versions: []apiextensionsv1.CustomResourceDefinitionVersion{ { Name: "v1alpha1", Served: true, Storage: true, Schema: &apiextensionsv1.CustomResourceValidation{ OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{ Type: "object", Properties: map[string]apiextensionsv1.JSONSchemaProps{ "spec": { Type: "object", Properties: map[string]apiextensionsv1.JSONSchemaProps{ "suspended": {Type: "boolean"}, }, }, "status": { Type: "object", Properties: map[string]apiextensionsv1.JSONSchemaProps{ "conditions": conditionSchema, }, }, }, }, }, Subresources: &apiextensionsv1.CustomResourceSubresources{ Status: &apiextensionsv1.CustomResourceSubresourceStatus{}, }, }, }, }, } // ClusterTestAppCRD is the programmatic CRD definition for the cluster-scoped ClusterTestApp. ClusterTestAppCRD = &apiextensionsv1.CustomResourceDefinition{ ObjectMeta: metav1.ObjectMeta{ Name: "clustertestapps.e2e.ocf.io", }, Spec: apiextensionsv1.CustomResourceDefinitionSpec{ Group: "e2e.ocf.io", Names: apiextensionsv1.CustomResourceDefinitionNames{ Kind: "ClusterTestApp", ListKind: "ClusterTestAppList", Plural: "clustertestapps", Singular: "clustertestapp", }, Scope: apiextensionsv1.ClusterScoped, Versions: []apiextensionsv1.CustomResourceDefinitionVersion{ { Name: "v1alpha1", Served: true, Storage: true, Schema: &apiextensionsv1.CustomResourceValidation{ OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{ Type: "object", Properties: map[string]apiextensionsv1.JSONSchemaProps{ "spec": { Type: "object", Properties: map[string]apiextensionsv1.JSONSchemaProps{ "suspended": {Type: "boolean"}, }, }, "status": { Type: "object", Properties: map[string]apiextensionsv1.JSONSchemaProps{ "conditions": conditionSchema, }, }, }, }, }, Subresources: &apiextensionsv1.CustomResourceSubresources{ Status: &apiextensionsv1.CustomResourceSubresourceStatus{}, }, }, }, }, } )
Functions ¶
func CreateTestNamespace ¶
CreateTestNamespace creates a namespace with GenerateName and returns its name.
func DeleteClusterTestApp ¶
DeleteClusterTestApp deletes the named ClusterTestApp from the cluster. It is intended for AfterEach cleanup since cluster-scoped resources are not garbage-collected by namespace deletion.
func GetClusterCondition ¶
func GetClusterCondition( ctx context.Context, c client.Client, name string, conditionType string, ) func(gomega.Gomega) *metav1.Condition
GetClusterCondition returns a closure that fetches a fresh ClusterTestApp from the cluster and returns the named condition. Suitable for use with gomega.Eventually.
func GetCondition ¶
func GetCondition( ctx context.Context, c client.Client, key types.NamespacedName, conditionType string, ) func(gomega.Gomega) *metav1.Condition
GetCondition returns a closure that fetches a fresh TestApp from the cluster and returns the named condition. Suitable for use with gomega.Eventually.
Usage:
Eventually(framework.GetCondition(ctx, c, key, "E2EReady")).
Should(framework.HaveConditionStatus(metav1.ConditionTrue, "Healthy"))
func HaveConditionStatus ¶
func HaveConditionStatus(status metav1.ConditionStatus, reason string) gomegatypes.GomegaMatcher
HaveConditionStatus returns a GomegaMatcher that checks a *metav1.Condition has the expected Status and Reason fields.
func InstallCRDs ¶
InstallCRDs applies both the TestApp and ClusterTestApp CRD definitions and waits until they are established.
Types ¶
type ClusterComponentFactory ¶
type ClusterComponentFactory func(owner *ClusterTestApp) (*component.Component, error)
ClusterComponentFactory builds a full *component.Component from the owner ClusterTestApp. Use this for multi-resource component tests where you need full control over the component configuration.
type ClusterE2EReconciler ¶
type ClusterE2EReconciler struct {
client.Client
Scheme *runtime.Scheme
Recorder record.EventRecorder
Metrics component.Recorder
// contains filtered or unexported fields
}
ClusterE2EReconciler is a controller-runtime reconciler that delegates component construction to per-test factories registered by name key. It reconciles cluster-scoped ClusterTestApp resources for testing cluster-scoped primitives.
func NewClusterE2EReconciler ¶
func NewClusterE2EReconciler( c client.Client, scheme *runtime.Scheme, recorder record.EventRecorder, metrics component.Recorder, ) *ClusterE2EReconciler
NewClusterE2EReconciler creates a new ClusterE2EReconciler.
func (*ClusterE2EReconciler) Reconcile ¶
func (r *ClusterE2EReconciler) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error)
Reconcile implements reconcile.Reconciler. It fetches the ClusterTestApp, looks up the registered factory, builds the component, and reconciles it.
func (*ClusterE2EReconciler) RegisterComponent ¶
func (r *ClusterE2EReconciler) RegisterComponent(name string, factory ClusterComponentFactory)
RegisterComponent registers a ClusterComponentFactory for a specific ClusterTestApp identified by its name. The factory is called on each reconciliation to build the full Component directly.
func (*ClusterE2EReconciler) RegisterResource ¶
func (r *ClusterE2EReconciler) RegisterResource(name string, factory ClusterResourceFactory)
RegisterResource registers a ClusterResourceFactory for a specific ClusterTestApp identified by its name. The factory is called on each reconciliation to build the resource, which is wrapped in a single-resource Component.
func (*ClusterE2EReconciler) Unregister ¶
func (r *ClusterE2EReconciler) Unregister(name string)
Unregister removes any registered factory for the given name.
type ClusterResourceFactory ¶
type ClusterResourceFactory func(owner *ClusterTestApp) (component.Resource, error)
ClusterResourceFactory builds a single component.Resource from the owner ClusterTestApp. The reconciler wraps the returned resource in a single-resource Component with condition type "E2EReady".
type ClusterTestApp ¶
type ClusterTestApp struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec TestAppSpec `json:"spec,omitempty"`
Status TestAppStatus `json:"status,omitempty"`
}
ClusterTestApp is the cluster-scoped CRD used as the owner object in E2E tests for cluster-scoped primitives (ClusterRole, ClusterRoleBinding, PersistentVolume).
func NewClusterTestApp ¶
NewClusterTestApp creates a cluster-scoped ClusterTestApp CR and returns it.
func (*ClusterTestApp) DeepCopy ¶
func (t *ClusterTestApp) DeepCopy() *ClusterTestApp
DeepCopy returns a deep copy of the ClusterTestApp.
func (*ClusterTestApp) DeepCopyInto ¶
func (t *ClusterTestApp) DeepCopyInto(out *ClusterTestApp)
DeepCopyInto copies all properties into another ClusterTestApp.
func (*ClusterTestApp) DeepCopyObject ¶
func (t *ClusterTestApp) DeepCopyObject() runtime.Object
DeepCopyObject implements runtime.Object.
func (*ClusterTestApp) GetKind ¶
func (t *ClusterTestApp) GetKind() string
GetKind returns the kind of the object.
func (*ClusterTestApp) GetStatusConditions ¶
func (t *ClusterTestApp) GetStatusConditions() *[]metav1.Condition
GetStatusConditions returns a pointer to the slice of status conditions.
type ClusterTestAppList ¶
type ClusterTestAppList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ClusterTestApp `json:"items"`
}
ClusterTestAppList contains a list of ClusterTestApp.
func (*ClusterTestAppList) DeepCopy ¶
func (t *ClusterTestAppList) DeepCopy() *ClusterTestAppList
DeepCopy returns a deep copy of the ClusterTestAppList.
func (*ClusterTestAppList) DeepCopyInto ¶
func (t *ClusterTestAppList) DeepCopyInto(out *ClusterTestAppList)
DeepCopyInto copies all properties into another ClusterTestAppList.
func (*ClusterTestAppList) DeepCopyObject ¶
func (t *ClusterTestAppList) DeepCopyObject() runtime.Object
DeepCopyObject implements runtime.Object.
type ComponentFactory ¶
ComponentFactory builds a full *component.Component from the owner TestApp. Use this for multi-resource component tests where you need full control over the component configuration.
type E2EReconciler ¶
type E2EReconciler struct {
client.Client
Scheme *runtime.Scheme
Recorder record.EventRecorder
Metrics component.Recorder
// contains filtered or unexported fields
}
E2EReconciler is a controller-runtime reconciler that delegates component construction to per-test factories registered by namespace/name key.
func NewE2EReconciler ¶
func NewE2EReconciler( c client.Client, scheme *runtime.Scheme, recorder record.EventRecorder, metrics component.Recorder, ) *E2EReconciler
NewE2EReconciler creates a new E2EReconciler.
func (*E2EReconciler) Reconcile ¶
func (r *E2EReconciler) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error)
Reconcile implements reconcile.Reconciler. It fetches the TestApp, looks up the registered factory, builds the component, and reconciles it.
func (*E2EReconciler) RegisterComponent ¶
func (r *E2EReconciler) RegisterComponent(key types.NamespacedName, factory ComponentFactory)
RegisterComponent registers a ComponentFactory for a specific TestApp identified by its namespaced name. The factory is called on each reconciliation to build the full Component directly.
func (*E2EReconciler) RegisterResource ¶
func (r *E2EReconciler) RegisterResource(key types.NamespacedName, factory ResourceFactory)
RegisterResource registers a ResourceFactory for a specific TestApp identified by its namespaced name. The factory is called on each reconciliation to build the resource, which is wrapped in a single-resource Component.
func (*E2EReconciler) Unregister ¶
func (r *E2EReconciler) Unregister(key types.NamespacedName)
Unregister removes any registered factory for the given namespaced name.
type ResourceFactory ¶
ResourceFactory builds a single component.Resource from the owner TestApp. The reconciler wraps the returned resource in a single-resource Component with condition type "E2EReady".
type TestApp ¶
type TestApp struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec TestAppSpec `json:"spec,omitempty"`
Status TestAppStatus `json:"status,omitempty"`
}
TestApp is the namespace-scoped CRD used as the owner object in E2E tests.
func NewTestApp ¶
NewTestApp creates a TestApp CR in the given namespace and returns it.
func (*TestApp) DeepCopyInto ¶
DeepCopyInto copies all properties into another TestApp.
func (*TestApp) DeepCopyObject ¶
DeepCopyObject implements runtime.Object.
func (*TestApp) GetStatusConditions ¶
GetStatusConditions returns a pointer to the slice of status conditions.
type TestAppList ¶
type TestAppList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []TestApp `json:"items"`
}
TestAppList contains a list of TestApp.
func (*TestAppList) DeepCopy ¶
func (t *TestAppList) DeepCopy() *TestAppList
DeepCopy returns a deep copy of the TestAppList.
func (*TestAppList) DeepCopyInto ¶
func (t *TestAppList) DeepCopyInto(out *TestAppList)
DeepCopyInto copies all properties into another TestAppList.
func (*TestAppList) DeepCopyObject ¶
func (t *TestAppList) DeepCopyObject() runtime.Object
DeepCopyObject implements runtime.Object.
type TestAppSpec ¶
type TestAppSpec struct {
// Suspended determines whether the application is suspended.
Suspended bool `json:"suspended,omitempty"`
}
TestAppSpec defines the desired state of TestApp.
type TestAppStatus ¶
type TestAppStatus struct {
// Conditions store the status of the application's components.
Conditions []metav1.Condition `json:"conditions,omitempty"`
}
TestAppStatus defines the observed state of TestApp.