Skip to content

Commit af48695

Browse files
committed
update test context.WithCancel with testing.T.Context
Signed-off-by: olalekan odukoya <[email protected]>
1 parent 896e5e9 commit af48695

28 files changed

+61
-133
lines changed

sdk/testing/kcp.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ limitations under the License.
1717
package testing
1818

1919
import (
20-
"context"
2120
"embed"
2221
"path/filepath"
22+
"testing"
2323

2424
"github.com/stretchr/testify/require"
2525

@@ -75,7 +75,7 @@ func PrivateKcpServer(t TestingT, options ...kcptestingserver.Option) kcptesting
7575
// `--kcp-kubeconfig` or `--use-default-kcp-server` is supplied to the test
7676
// runner. Otherwise a test-managed server will be started. Only tests
7777
// that are known to be hermetic are compatible with shared fixture.
78-
func SharedKcpServer(t TestingT) kcptestingserver.RunningServer {
78+
func SharedKcpServer(t *testing.T) kcptestingserver.RunningServer {
7979
t.Helper()
8080

8181
setupExternal()
@@ -86,8 +86,7 @@ func SharedKcpServer(t TestingT) kcptestingserver.RunningServer {
8686
s, err := kcptestingserver.NewExternalKCPServer(sharedConfig.Name, externalConfig.kubeconfigPath, externalConfig.shardKubeconfigPaths, filepath.Dir(KubeconfigPath()))
8787
require.NoError(t, err, "failed to create persistent server fixture")
8888

89-
ctx, cancel := context.WithCancel(context.Background())
90-
t.Cleanup(cancel)
89+
ctx := t.Context()
9190

9291
rootCfg := s.RootShardSystemMasterBaseConfig(t)
9392
t.Logf("Waiting for readiness for server at %s", rootCfg.Host)

test/e2e/apibinding/apibinding_deletion_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ func TestAPIBindingDeletion(t *testing.T) {
5353

5454
server := kcptesting.SharedKcpServer(t)
5555

56-
ctx, cancel := context.WithCancel(context.Background())
57-
t.Cleanup(cancel)
56+
ctx := t.Context()
5857

5958
orgPath, _ := kcptesting.NewWorkspaceFixture(t, server, core.RootCluster.Path(), kcptesting.WithType(core.RootCluster.Path(), "organization"))
6059
providerPath, _ := kcptesting.NewWorkspaceFixture(t, server, orgPath)

test/e2e/apibinding/apibinding_logicalcluster_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package apibinding
1818

1919
import (
20-
"context"
2120
"fmt"
2221
"testing"
2322
"time"
@@ -60,8 +59,7 @@ func TestAPIBindingLogicalCluster(t *testing.T) {
6059
t.Logf("providerPath: %v", providerPath)
6160
t.Logf("consumerPath: %v", consumerPath)
6261

63-
ctx, cancel := context.WithCancel(context.Background())
64-
t.Cleanup(cancel)
62+
ctx := t.Context()
6563

6664
cfg := server.BaseConfig(t)
6765

@@ -193,8 +191,7 @@ func TestAPIBindingCRDs(t *testing.T) {
193191
t.Logf("providerPath: %v", providerPath)
194192
t.Logf("consumerPath: %v", consumerPath)
195193

196-
ctx, cancel := context.WithCancel(context.Background())
197-
t.Cleanup(cancel)
194+
ctx := t.Context()
198195

199196
cfg := server.BaseConfig(t)
200197

test/e2e/apibinding/apibinding_permissionclaims_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ func TestAPIBindingPermissionClaimsConditions(t *testing.T) {
5555

5656
server := kcptesting.SharedKcpServer(t)
5757

58-
ctx, cancel := context.WithCancel(context.Background())
59-
t.Cleanup(cancel)
58+
ctx := t.Context()
6059

6160
orgPath, _ := kcptesting.NewWorkspaceFixture(t, server, core.RootCluster.Path(), kcptesting.WithType(core.RootCluster.Path(), "organization"))
6261
providerPath, _ := kcptesting.NewWorkspaceFixture(t, server, orgPath)

test/e2e/apibinding/apibinding_protected_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package apibinding
1818

1919
import (
20-
"context"
2120
"fmt"
2221
"testing"
2322
"time"
@@ -47,8 +46,7 @@ func TestProtectedAPI(t *testing.T) {
4746

4847
server := kcptesting.SharedKcpServer(t)
4948

50-
ctx, cancel := context.WithCancel(context.Background())
51-
t.Cleanup(cancel)
49+
ctx := t.Context()
5250

5351
orgPath, _ := kcptesting.NewWorkspaceFixture(t, server, core.RootCluster.Path(), kcptesting.WithType(core.RootCluster.Path(), "organization"))
5452
providerPath, _ := kcptesting.NewWorkspaceFixture(t, server, orgPath)

test/e2e/apibinding/apibinding_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ func TestAPIBindingAPIExportReferenceImmutability(t *testing.T) {
6767

6868
server := kcptesting.SharedKcpServer(t)
6969

70-
ctx, cancel := context.WithCancel(context.Background())
71-
t.Cleanup(cancel)
70+
ctx := t.Context()
7271

7372
orgPath, _ := kcptesting.NewWorkspaceFixture(t, server, core.RootCluster.Path(), kcptesting.WithType(core.RootCluster.Path(), "organization"))
7473
providerPath, _ := kcptesting.NewWorkspaceFixture(t, server, orgPath, kcptesting.WithName("service-provider-1"))
@@ -167,8 +166,7 @@ func TestAPIBinding(t *testing.T) {
167166
server := kcptesting.SharedKcpServer(t)
168167
cfg := server.BaseConfig(t)
169168

170-
ctx, cancel := context.WithCancel(context.Background())
171-
t.Cleanup(cancel)
169+
ctx := t.Context()
172170

173171
t.Logf("Check if we can access shards")
174172
var shards *corev1alpha1.ShardList

test/e2e/apibinding/apibinding_webhook_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package apibinding
1818

1919
import (
20-
"context"
2120
"crypto/tls"
2221
"fmt"
2322
gohttp "net/http"
@@ -62,8 +61,7 @@ func TestAPIBindingMutatingWebhook(t *testing.T) {
6261

6362
server := kcptesting.SharedKcpServer(t)
6463

65-
ctx, cancel := context.WithCancel(context.Background())
66-
t.Cleanup(cancel)
64+
ctx := t.Context()
6765

6866
orgPath, _ := kcptesting.NewWorkspaceFixture(t, server, core.RootCluster.Path(), kcptesting.WithType(core.RootCluster.Path(), "organization"))
6967
sourcePath, sourceWS := kcptesting.NewWorkspaceFixture(t, server, orgPath)
@@ -247,8 +245,7 @@ func TestAPIBindingValidatingWebhook(t *testing.T) {
247245

248246
server := kcptesting.SharedKcpServer(t)
249247

250-
ctx, cancel := context.WithCancel(context.Background())
251-
t.Cleanup(cancel)
248+
ctx := t.Context()
252249

253250
orgPath, _ := kcptesting.NewWorkspaceFixture(t, server, core.RootCluster.Path(), kcptesting.WithType(core.RootCluster.Path(), "organization"))
254251
sourcePath, sourceWS := kcptesting.NewWorkspaceFixture(t, server, orgPath)

test/e2e/apibinding/default_apibinding_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package apibinding
1818

1919
import (
20-
"context"
2120
"fmt"
2221
"slices"
2322
"strings"
@@ -57,8 +56,7 @@ func TestDefaultAPIBinding(t *testing.T) {
5756

5857
t.Logf("providerPath: %v", providerPath)
5958

60-
ctx, cancel := context.WithCancel(context.Background())
61-
t.Cleanup(cancel)
59+
ctx := t.Context()
6260

6361
cfg := server.BaseConfig(t)
6462

test/e2e/apibinding/maximalpermissionpolicy_authorizer_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ func TestMaximalPermissionPolicyAuthorizerSystemGroupProtection(t *testing.T) {
5757

5858
server := kcptesting.SharedKcpServer(t)
5959

60-
ctx, cancel := context.WithCancel(context.Background())
61-
t.Cleanup(cancel)
60+
ctx := t.Context()
6261

6362
kubeClusterClient, err := kcpkubernetesclientset.NewForConfig(server.BaseConfig(t))
6463
require.NoError(t, err, "failed to construct dynamic cluster client for server")
@@ -152,8 +151,7 @@ func TestMaximalPermissionPolicyAuthorizer(t *testing.T) {
152151

153152
server := kcptesting.SharedKcpServer(t)
154153

155-
ctx, cancel := context.WithCancel(context.Background())
156-
t.Cleanup(cancel)
154+
ctx := t.Context()
157155

158156
orgPath, _ := kcptesting.NewWorkspaceFixture(t, server, core.RootCluster.Path(), kcptesting.WithType(core.RootCluster.Path(), "organization"))
159157
rbacServiceProviderPath, _ := kcptesting.NewWorkspaceFixture(t, server, orgPath)

test/e2e/authorizer/scopes_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package authorizer
1818

1919
import (
20-
"context"
2120
"fmt"
2221
"sort"
2322
"testing"
@@ -136,8 +135,7 @@ func TestSubjectAccessReview(t *testing.T) {
136135
wantAllowed: true},
137136
} {
138137
t.Run(tt.name, func(t *testing.T) {
139-
ctx, cancel := context.WithCancel(context.Background())
140-
defer cancel()
138+
ctx := t.Context()
141139

142140
req := &authorizationv1.SubjectAccessReview{
143141
Spec: authorizationv1.SubjectAccessReviewSpec{
@@ -166,8 +164,7 @@ func TestSelfSubjectRulesReview(t *testing.T) {
166164
t.Parallel()
167165
framework.Suite(t, "control-plane")
168166

169-
ctx, cancel := context.WithCancel(context.Background())
170-
defer cancel()
167+
ctx := t.Context()
171168

172169
server := kcptesting.SharedKcpServer(t)
173170
cfg := server.BaseConfig(t)
@@ -285,8 +282,7 @@ func TestSelfSubjectRulesReview(t *testing.T) {
285282
},
286283
} {
287284
t.Run(tt.name, func(t *testing.T) {
288-
ctx, cancel := context.WithCancel(context.Background())
289-
defer cancel()
285+
ctx := t.Context()
290286

291287
// impersonate as user, using the cfg as the base.
292288
impersonationConfig := rest.CopyConfig(cfg)

0 commit comments

Comments
 (0)