Documentation ¶
Index ¶
- Variables
- func CreateGatekeeperNamespace(cfg *rest.Config) error
- func CreateThenCleanup(ctx context.Context, t *testing.T, c client.Client, obj client.Object)
- func DeleteObject(t *testing.T, c client.Client, original client.Object) func()
- func DeleteObjectAndConfirm(ctx context.Context, t *testing.T, c client.Client, obj client.Object) func()
- func NewLogger(t *testing.T) logr.Logger
- func Setenv(t *testing.T, key, value string)
- func SetupManager(t *testing.T, cfg *rest.Config) (manager.Manager, *watch.Manager)
- func StartControlPlane(m *testing.M, cfg **rest.Config, testerDepth int)
- func StartManager(ctx context.Context, t *testing.T, mgr manager.Manager)
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ConstantRetry = wait.Backoff{ Steps: 3000, Duration: 10 * time.Millisecond, }
ConstantRetry makes 3,000 attempts at a rate of 100 per second. Since this is a test instance and not a "real" cluster, this is fine and there's no need to increase the wait time each iteration.
Functions ¶
func CreateGatekeeperNamespace ¶
CreateGatekeeperNamespace bootstraps the gatekeeper-system namespace for use in tests.
func CreateThenCleanup ¶
CreateThenCleanup creates obj in Client, and then registers obj to be deleted at the end of the test. The passed obj is safely deepcopied before being passed to client.Create, so it is not mutated by this call.
func DeleteObject ¶
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 DeleteObjectAndConfirm ¶
func DeleteObjectAndConfirm(ctx context.Context, t *testing.T, c client.Client, obj client.Object) func()
DeleteObjectAndConfirm returns a callback which deletes obj from the passed Client. Does result in mutations to obj. The callback includes a cached copy of all information required to delete obj in the callback, so it is safe to mutate obj afterwards. Similarly - client.Delete mutates its input, but the callback does not call client.Delete on obj. Instead, it creates a single-purpose Unstructured for this purpose. Thus, obj is not mutated after the callback is run.
func NewLogger ¶
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 ¶
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 SetupManager ¶
SetupManager sets up a controller-runtime manager with registered watch manager.