type Underlier … const CleanupGracePeriod … type TContext … type TB … type ContextTB … // Init can be called in a unit or integration test to create // a test context which: // - has a per-test logger with verbosity derived from the -v command line flag // - gets canceled when the test finishes (via [TB.Cleanup]) // // Note that the test context supports the interfaces of [TB] and // [context.Context] and thus can be used like one of those where needed. // It also has additional methods for retrieving the logger and canceling // the context early, which can be useful in tests which want to wait // for goroutines to terminate after cancellation. // // If the [TB] implementation also implements [ContextTB], then // [TContext.CleanupCtx] uses [ContextTB.CleanupCtx] and uses // the context passed into that callback. This can be used to let // Ginkgo create a fresh context for cleanup code. // // Can be called more than once per test to get different contexts with // independent cancellation. The default behavior describe above can be // modified via optional functional options defined in [initoption]. func Init(tb TB, opts ...InitOption) TContext { … } type InitOption … // InitCtx is a variant of [Init] which uses an already existing context and // whatever logger and timeouts are stored there. // Functional options are part of the API, but currently // there are none which have an effect. func InitCtx(ctx context.Context, tb TB, _ ...InitOption) TContext { … } // WithTB constructs a new TContext with a different TB instance. // This can be used to set up some of the context, in particular // clients, in the root test and then run sub-tests: // // func TestSomething(t *testing.T) { // tCtx := ktesting.Init(t) // ... // tCtx = ktesting.WithRESTConfig(tCtx, config) // // t.Run("sub", func (t *testing.T) { // tCtx := ktesting.WithTB(tCtx, t) // ... // }) // // WithTB sets up cancellation for the sub-test. func WithTB(parentCtx TContext, tb TB) TContext { … } // WithContext constructs a new TContext with a different Context instance. // This can be used in callbacks which receive a Context, for example // from Gomega: // // gomega.Eventually(tCtx, func(ctx context.Context) { // tCtx := ktesting.WithContext(tCtx, ctx) // ... // // This is important because the Context in the callback could have // a different deadline than in the parent TContext. func WithContext(parentCtx TContext, ctx context.Context) TContext { … } // WithValue wraps context.WithValue such that the result is again a TContext. func WithValue(parentCtx TContext, key, val any) TContext { … } type tContext … type testingTB … func (tCtx tContext) Cancel(cause string) { … } func (tCtx tContext) CleanupCtx(cb func(TContext)) { … } func (tCtx tContext) Expect(actual interface{ … } func (tCtx tContext) ExpectNoError(err error, explain ...interface{ … } func cleanupCtx(tCtx TContext, cb func(TContext)) { … } func (tCtx tContext) Logger() klog.Logger { … } func (tCtx tContext) Error(args ...any) { … } func (tCtx tContext) Errorf(format string, args ...any) { … } func (tCtx tContext) Fatal(args ...any) { … } func (tCtx tContext) Fatalf(format string, args ...any) { … } func (tCtx tContext) TB() TB { … } func (tCtx tContext) RESTConfig() *rest.Config { … } func (tCtx tContext) RESTMapper() *restmapper.DeferredDiscoveryRESTMapper { … } func (tCtx tContext) Client() clientset.Interface { … } func (tCtx tContext) Dynamic() dynamic.Interface { … } func (tCtx tContext) APIExtensions() apiextensions.Interface { … }