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

@@ -136,9 +136,7 @@ func TestClientCARecreate(t *testing.T) {
}
func testClientCA(t *testing.T, recreate bool) {
_, ctx := ktesting.NewTestContext(t)
ctx, cancel := context.WithCancel(ctx)
defer cancel()
tCtx := ktesting.Init(t)
frontProxyCA, err := newTestCAWithClient(
pkix.Name{
@@ -175,7 +173,7 @@ func testClientCA(t *testing.T, recreate bool) {
clientCAFilename := ""
frontProxyCAFilename := ""
kubeClient, kubeconfig, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
kubeClient, kubeconfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
opts.GenericServerRunOptions.MaxRequestBodyBytes = 1024 * 1024
clientCAFilename = opts.Authentication.ClientCert.ClientCA
@@ -305,7 +303,7 @@ func testClientCA(t *testing.T, recreate bool) {
}
// Call an endpoint to make sure we are authenticated
_, err = testClient.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
_, err = testClient.CoreV1().Nodes().List(tCtx, metav1.ListOptions{})
if err != nil {
t.Error(err)
}
@@ -473,13 +471,11 @@ func TestServingCertRecreate(t *testing.T) {
}
func testServingCert(t *testing.T, recreate bool) {
_, ctx := ktesting.NewTestContext(t)
ctx, cancel := context.WithCancel(ctx)
defer cancel()
tCtx := ktesting.Init(t)
var servingCertPath string
_, kubeconfig, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
_, kubeconfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
opts.GenericServerRunOptions.MaxRequestBodyBytes = 1024 * 1024
servingCertPath = opts.SecureServing.ServerCert.CertDirectory
@@ -518,11 +514,9 @@ func testServingCert(t *testing.T, recreate bool) {
func TestSNICert(t *testing.T) {
var servingCertPath string
_, ctx := ktesting.NewTestContext(t)
ctx, cancel := context.WithCancel(ctx)
defer cancel()
tCtx := ktesting.Init(t)
_, kubeconfig, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
_, kubeconfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
opts.GenericServerRunOptions.MaxRequestBodyBytes = 1024 * 1024
servingCertPath = opts.SecureServing.ServerCert.CertDirectory