From 61a08b94dc7fe81a43982a00c048cc6e1bf5c15c Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Mon, 2 Feb 2026 16:35:11 +0100 Subject: [PATCH] ktesting: remove deprecated and unused functions They were replaced with methods and after their usage got updated can now also be removed. --- test/utils/ktesting/assert.go | 12 ------------ test/utils/ktesting/clientcontext.go | 10 ---------- test/utils/ktesting/errorcontext.go | 5 ----- test/utils/ktesting/stepcontext.go | 11 ----------- test/utils/ktesting/tcontext.go | 14 ++------------ test/utils/ktesting/withcontext.go | 16 ---------------- 6 files changed, 2 insertions(+), 66 deletions(-) diff --git a/test/utils/ktesting/assert.go b/test/utils/ktesting/assert.go index a843db8f4fe..2f6bbca8a4e 100644 --- a/test/utils/ktesting/assert.go +++ b/test/utils/ktesting/assert.go @@ -164,12 +164,6 @@ func buildDescription(explain ...interface{}) string { return fmt.Sprintf(explain[0].(string), explain[1:]...) } -// Deprecated: use tCtx.Eventually instead. -func Eventually[T any](tCtx TContext, cb func(TContext) T) gomega.AsyncAssertion { - tCtx.Helper() - return tCtx.Eventually(cb) -} - // Eventually wraps [gomega.Eventually]. Supported argument types are: // - A function with a `tCtx ktesting.TContext` or `ctx context.Context` // parameter plus additional parameters and arbitrary return values. @@ -251,12 +245,6 @@ func (tc *TC) AssertEventually(arg any) gomega.AsyncAssertion { return tc.newAsyncAssertion(gomega.NewWithT(assertTestingT{tc}).Eventually, arg) } -// Deprecated: use tCtx.Consistently instead. -func Consistently[T any](tCtx TContext, cb func(TContext) T) gomega.AsyncAssertion { - tCtx.Helper() - return tCtx.Consistently(cb) -} - // Consistently wraps [gomega.Consistently] the same way as [Eventually] wraps // [gomega.Eventually]. func (tc *TC) Consistently(arg any) gomega.AsyncAssertion { diff --git a/test/utils/ktesting/clientcontext.go b/test/utils/ktesting/clientcontext.go index 777adffea75..e8555125caf 100644 --- a/test/utils/ktesting/clientcontext.go +++ b/test/utils/ktesting/clientcontext.go @@ -27,11 +27,6 @@ import ( "k8s.io/client-go/restmapper" ) -// Deprecated: use tCtx.WithRESTConfig instead -func WithRESTConfig(tCtx TContext, cfg *rest.Config) TContext { - return tCtx.WithRESTConfig(cfg) -} - // WithRESTConfig initializes all client-go clients with new clients // created for the config. The current test name gets included in the UserAgent. func (tc *TC) WithRESTConfig(cfg *rest.Config) TContext { @@ -48,11 +43,6 @@ func (tc *TC) WithRESTConfig(cfg *rest.Config) TContext { return tc } -// Deprecated: use tCtx.WithClients instead -func WithClients(tCtx TContext, cfg *rest.Config, mapper *restmapper.DeferredDiscoveryRESTMapper, client clientset.Interface, dynamic dynamic.Interface, apiextensions apiextensions.Interface) TContext { - return tCtx.WithClients(cfg, mapper, client, dynamic, apiextensions) -} - // WithClients uses an existing config and clients. func (tc *TC) WithClients(cfg *rest.Config, mapper *restmapper.DeferredDiscoveryRESTMapper, client clientset.Interface, dynamic dynamic.Interface, apiextensions apiextensions.Interface) TContext { tc = tc.clone() diff --git a/test/utils/ktesting/errorcontext.go b/test/utils/ktesting/errorcontext.go index 85dd3a3c821..d8fd8a340b0 100644 --- a/test/utils/ktesting/errorcontext.go +++ b/test/utils/ktesting/errorcontext.go @@ -22,11 +22,6 @@ import ( "strings" ) -// Deprecated: use tCtx.WithError instead -func WithError(tCtx TContext, err *error) (TContext, func()) { - return tCtx.WithError(err) -} - // WithError creates a context where test failures are collected and stored in // the provided error instance when the caller is done. Use it like this: // diff --git a/test/utils/ktesting/stepcontext.go b/test/utils/ktesting/stepcontext.go index 834217a35b9..34ed5e57b6a 100644 --- a/test/utils/ktesting/stepcontext.go +++ b/test/utils/ktesting/stepcontext.go @@ -16,11 +16,6 @@ limitations under the License. package ktesting -// Deprecated: use tCtx.WithStep instead -func WithStep(tCtx TContext, step string) TContext { - return tCtx.WithStep(step) -} - // WithStep creates a context where a prefix is added to all errors and log // messages, similar to how errors are wrapped. This can be nested, leaving a // trail of "bread crumbs" that help figure out where in a test some problem @@ -37,12 +32,6 @@ func (tc *TC) WithStep(step string) *TC { return tc } -// Deprecated: use tCtx.Step instead -func Step(tCtx TContext, step string, cb func(tCtx TContext)) { - tCtx.Helper() - tCtx.Step(step, cb) -} - // Step is useful when the context with the step information is // used more than once: // diff --git a/test/utils/ktesting/tcontext.go b/test/utils/ktesting/tcontext.go index ff5b1cd5f44..db9ffbe9718 100644 --- a/test/utils/ktesting/tcontext.go +++ b/test/utils/ktesting/tcontext.go @@ -296,11 +296,6 @@ func run(tc *TC, name string, syncTest bool, cb func(tc *TC)) bool { return false } -// Deprecated: use tCtx.WithContext instead -func WithContext(tCtx TContext, ctx context.Context) TContext { - return tCtx.WithContext(ctx) -} - // WithContext constructs a new TContext with a different Context instance. // This can be used in callbacks which receive a Context, for example // from Gomega: @@ -322,11 +317,6 @@ func (tc *TC) WithContext(ctx context.Context) TContext { return tc } -// Deprecated: use tCtx.WithValue instead -func WithValue(tCtx TContext, key, val any) TContext { - return tCtx.WithValue(key, val) -} - // WithValue wraps [context.WithValue] such that the result is again a TContext. func (tc *TC) WithValue(key, val any) TContext { ctx := context.WithValue(tc, key, val) @@ -480,7 +470,7 @@ func (tc *TC) CleanupCtx(cb func(TContext)) { if tb, ok := tc.TB().(ContextTB); ok { // Use context from base TB (most likely Ginkgo). tb.CleanupCtx(func(ctx context.Context) { - tCtx := WithContext(tc, ctx) + tCtx := tc.WithContext(ctx) cb(tCtx) }) return @@ -491,7 +481,7 @@ func (tc *TC) CleanupCtx(cb func(TContext)) { // context then has *no* deadline. In the code path above for // Ginkgo, Ginkgo is more sophisticated and also applies // timeouts to cleanup calls which accept a context. - childCtx := WithContext(tc, context.WithoutCancel(tc)) + childCtx := tc.WithContext(context.WithoutCancel(tc)) cb(childCtx) }) } diff --git a/test/utils/ktesting/withcontext.go b/test/utils/ktesting/withcontext.go index 2b6e1980e74..5a87aad48ca 100644 --- a/test/utils/ktesting/withcontext.go +++ b/test/utils/ktesting/withcontext.go @@ -23,9 +23,6 @@ import ( "k8s.io/klog/v2" ) -// Deprecated: use tCtx.WithCancel instead -func WithCancel(tCtx TContext) TContext { return tCtx.WithCancel() } - // WithCancel sets up cancellation in a [TContext.Cleanup] callback and // constructs a new TContext where [TContext.Cancel] cancels only the new // context. @@ -44,9 +41,6 @@ func (tc *TC) WithCancel() TContext { return tc } -// Deprecated: use tCtx.WithoutCancel instead -func WithoutCancel(tCtx TContext) TContext { return tCtx.WithoutCancel() } - // WithoutCancel causes the returned context to ignore cancellation of its parent. // Calling Cancel will not cancel the parent either. // This matches [context.WithoutCancel]. @@ -59,11 +53,6 @@ func (tc *TC) WithoutCancel() TContext { return tc } -// Deprecated: use tCtx.WithTimeout instead -func WithTimeout(tCtx TContext, timeout time.Duration, timeoutCause string) TContext { - return tCtx.WithTimeout(timeout, timeoutCause) -} - // WithTimeout sets up new context with a timeout. Canceling the timeout gets // registered in a cleanup callback. [TContext.Cancel] cancels only // the new context. The cause is used as reason why the context is canceled @@ -78,11 +67,6 @@ func (tc *TC) WithTimeout(timeout time.Duration, timeoutCause string) TContext { return tc } -// Deprecated: used tCtx.WithLogger instead -func WithLogger(tCtx TContext, logger klog.Logger) TContext { - return tCtx.WithLogger(logger) -} - // WithLogger constructs a new context with a different logger. func (tc *TC) WithLogger(logger klog.Logger) TContext { ctx := klog.NewContext(tc, logger)