Documentation ¶
Index ¶
- type TestEnvironment
- func (t *TestEnvironment) Cleanup(ctx context.Context, objs ...client.Object) error
- func (t *TestEnvironment) CreateNamespace(ctx context.Context, generateName string) (*corev1.Namespace, error)
- func (t *TestEnvironment) CreateNamespaceWithName(ctx context.Context, name string) (*corev1.Namespace, error)
- func (t *TestEnvironment) GetAs(obj, as client.Object) func() (client.Object, error)
- func (t *TestEnvironment) GetKeyAs(key client.ObjectKey, as client.Object) func() (client.Object, error)
- func (t *TestEnvironment) KeyAs(key client.ObjectKey, to client.Object) client.Object
- func (t *TestEnvironment) StartManager(ctx context.Context) error
- func (t *TestEnvironment) Stop() error
- type TestEnvironmentConfiguration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TestEnvironment ¶
type TestEnvironment struct { manager.Manager client.Client Config *rest.Config // contains filtered or unexported fields }
TestEnvironment encapsulates a Kubernetes local test environment.
func (*TestEnvironment) CreateNamespace ¶
func (t *TestEnvironment) CreateNamespace(ctx context.Context, generateName string) (*corev1.Namespace, error)
CreateNamespace creates a new namespace with a generated name.
func (*TestEnvironment) CreateNamespaceWithName ¶
func (t *TestEnvironment) CreateNamespaceWithName(ctx context.Context, name string) (*corev1.Namespace, error)
CreateNamespaceWithName creates a new namespace with a given name.
func (*TestEnvironment) GetAs ¶
GetAs is a wrapper on komega.Object helper, allowing to construct a new object from an existing object metadata and match for object state in kubernetes cluster. Example:
// Expecting cluster to be present in the kubernetes API server and be stored in &provisioningv1.Cluster{}. // rancherCluster will not be modified during this operation g.Eventually(testEnv.GetKeyAs(rancherCluster, &provisioningv1.Cluster{})).ShouldNot(BeNil())
func (*TestEnvironment) GetKeyAs ¶
func (t *TestEnvironment) GetKeyAs(key client.ObjectKey, as client.Object) func() (client.Object, error)
GetKeyAs is a wrapper on komega.Object helper, allowing to construct a new object from a key and match for object state in kubernetes cluster. Example:
// Expecting cluster to be present in the kubernetes API server and be stored in &provisioningv1.Cluster{} rancherClusterKey := types.NamespaceName{Name: "cluster", Namespace: "default"} g.Eventually(testEnv.GetKeyAs(rancherClusterKey, &provisioningv1.Cluster{})).ShouldNot(BeNil())
func (*TestEnvironment) KeyAs ¶
KeyAs is an opposite of client.ObjectKeyFromObject, to construct a new client.Object from provider namespace/name. Example:
emptyCluster := testEnv.KeyAs(client.ObjectKeyFromObject(rancherCluster), &provisioningv1.Cluster{}) Expect(cl.Get(ctx, emptyCluster)).To(Succeed())
func (*TestEnvironment) StartManager ¶
func (t *TestEnvironment) StartManager(ctx context.Context) error
StartManager starts the test controller against the local API server.
func (*TestEnvironment) Stop ¶
func (t *TestEnvironment) Stop() error
Stop stops the test environment.
type TestEnvironmentConfiguration ¶
type TestEnvironmentConfiguration struct {
// contains filtered or unexported fields
}
TestEnvironmentConfiguration is a wrapper configuration for envtest.
func NewTestEnvironmentConfiguration ¶
func NewTestEnvironmentConfiguration(crdDirectoryPaths ...string) *TestEnvironmentConfiguration
NewTestEnvironmentConfiguration creates a new test environment configuration for running tests.
func (*TestEnvironmentConfiguration) Build ¶
func (t *TestEnvironmentConfiguration) Build() (*TestEnvironment, error)
Build creates a new environment spinning up a local api-server. This function should be called only once for each package you're running tests within, usually the environment is initialized in a suite_test.go file within a `BeforeSuite` ginkgo block.