Documentation ¶
Overview ¶
Package helpers provides a set of utilities for testing controllers.
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) GetK8sClient() (client.Client, error)
- func (t *TestEnvironment) GetK8sClientWithScheme(clientScheme *runtime.Scheme) (client.Client, error)
- 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.
var TestEnv *TestEnvironment
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) GetK8sClient ¶
func (t *TestEnvironment) GetK8sClient() (client.Client, error)
GetK8sClient returns a “live” k8s client that does will not invoke against controller cache. If a test is writing an object, they are not immediately available to read since controller caches are not synchronized yet.
func (*TestEnvironment) GetK8sClientWithScheme ¶ added in v0.8.0
func (t *TestEnvironment) GetK8sClientWithScheme( clientScheme *runtime.Scheme, ) (client.Client, error)
GetK8sClientWithScheme - same as GetK8sClient but can pass in a configurable scheme.
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
}
func NewTestEnvironmentConfiguration ¶
func NewTestEnvironmentConfiguration() *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.