test: use cancelation from ktesting

The return type of ktesting.NewTestContext is now a TContext. Code
which combined it WithCancel often didn't compile anymore (cannot overwrite
ktesting.TContext with context.Context). This is a good thing because all of
that code can be simplified to let ktesting handle the cancelation.
This commit is contained in:
Patrick Ohly
2023-12-25 19:40:56 +01:00
parent 3df07e446b
commit 1d653e6185
34 changed files with 458 additions and 695 deletions

View File

@@ -17,7 +17,6 @@ limitations under the License.
package ktesting
import (
"context"
"flag"
"fmt"
"testing"
@@ -41,14 +40,9 @@ func SetDefaultVerbosity(v int) {
_ = f.Value.Set(fmt.Sprintf("%d", v))
}
// NewTestContext is a drop-in replacement for ktesting.NewTestContext
// NewTestContext is a replacement for ktesting.NewTestContext
// which returns a more versatile context.
//
// The type of that context is still context.Context because replacing
// it with TContext breaks tests which use `WithCancel`.
//
// TODO(pohly): change all of that code together with changing the return type.
func NewTestContext(tb testing.TB) (klog.Logger, context.Context) {
func NewTestContext(tb testing.TB) (klog.Logger, TContext) {
tCtx := Init(tb)
return tCtx.Logger(), tCtx
}