testutils

package
v3.9.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteObject

func DeleteObject(t *testing.T, c client.Client, original client.Object) func()

DeleteObject deletes obj from c. Succeeds on success or if obj already did not exist in c. Fails the test if calling Delete() returns an error other than NotFound.

Does not ensure the object is actually deleted, just sends a delete request via the passed Client. See #1596 for why this is non-trivial to guarantee.

Tests should not rely on objects being deleted from the API Server which were used in other tests; they should instead use unique object names and namespaces to eliminate cross-talk. More explicitly: if you are writing a test which must make use of this cleanup function, you are risking cross-talk between tests and should instead modify your test.

func NewLogger

func NewLogger(t *testing.T) logr.Logger

NewLogger creates a logger specifically for t which logs directly to the test. Use test-specific loggers so that when tests fail, only the log messages from the offending test are printed rather than log messages for every test in the package.

func Setenv

func Setenv(t *testing.T, key, value string)

Setenv sets os environment variable key to value. Registers the environment variable to be set to its original value at the end of the test.

This prevents cross-talk between tests, as some may implicitly come to rely on other tests running before them in order to succeed.

func StartManager

func StartManager(ctx context.Context, t *testing.T, mgr manager.Manager)

StartManager starts mgr. Registers a cleanup function to stop the manager at the completion of the test.

Types

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

func NewTestWriter

func NewTestWriter(t *testing.T) *Writer

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL