Documentation ¶
Index ¶
- Constants
- func Context(t *testing.T, ctx context.Context) (context.Context, context.CancelFunc)
- func DumpLogsIfTestFailed(t *testing.T, logs LogsObserver)
- func NameFromT(t *testing.T) string
- func NewControllerClient(t *testing.T, scheme *runtime.Scheme, cfg *rest.Config) ctrlclient.Client
- func Setup(t *testing.T, ctx context.Context, scheme *k8sruntime.Scheme) (*rest.Config, *corev1.Namespace)
- func StartReconcilers(ctx context.Context, t *testing.T, mgr manager.Manager, logs LogsObserver, ...)
- type LogsObserver
- type Reconciler
Constants ¶
const ( // ErrBodyDataConstraintError is a JSON error response body for a data constraint error. ErrBodyDataConstraintError = `` /* 291-byte string literal not displayed */ )
Variables ¶
This section is empty.
Functions ¶
func Context ¶
Context creates a context for tests with deadline if it was provided. It also cancels the context on test cleanup.
func DumpLogsIfTestFailed ¶
func DumpLogsIfTestFailed(t *testing.T, logs LogsObserver)
DumpLogsIfTestFailed dumps the provided logs the if the test failed.
func NameFromT ¶
NameFromT returns a name suitable for use in Kubernetes resources for a given test. This is used e.g. when setting kong addon's name.
func NewControllerClient ¶
NewControllerClient returns a new controller-runtime Client for provided runtime.Scheme and rest.Config.
func Setup ¶
func Setup(t *testing.T, ctx context.Context, scheme *k8sruntime.Scheme) (*rest.Config, *corev1.Namespace)
Setup sets up a test k8s API server environment and returned the configuration.
func StartReconcilers ¶
func StartReconcilers( ctx context.Context, t *testing.T, mgr manager.Manager, logs LogsObserver, reconcilers ...Reconciler, )
StartReconcilers creates a controller manager and starts the provided reconciler as its runnable. It also adds a t.Cleanup which waits for the manager to exit so that the test can be self contained and logs from different tests' managers don't mix up.
Types ¶
type LogsObserver ¶
type LogsObserver interface { // All returns all the logs that have been observed so far. All() []observer.LoggedEntry }
LogsObserver is an interface for observing logs.
func CreateTestLogger ¶
CreateTestLogger creates a logger for use in tests. It returns the logger - which is also added to the context - and the observer which can be used to dump logs if the test fails.
func NewManager ¶
func NewManager(t *testing.T, ctx context.Context, cfg *rest.Config, s *runtime.Scheme) (manager.Manager, LogsObserver)
NewManager returns a manager and a logs observer. The logs observer can be used to dump logs if the test fails. The returned manager can be used with StartReconcilers() to start a list of provided reconcilers with the manager.