Skip to content

Commit c2a4c7a

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

File tree

48 files changed

+81
-191
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+81
-191
lines changed

config/crds/bootstrap_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ func TestCreateFromFS(t *testing.T) {
3939
{
4040
name: "context cancelled",
4141
ctx: func() context.Context {
42-
ctx, cancel := context.WithCancel(context.TODO())
43-
cancel()
44-
return ctx
42+
return t.Context()
4543
}(),
4644
grs: []metav1.GroupResource{
4745
{Group: tenancy.GroupName, Resource: "workspaces"},

pkg/authentication/index_test.go

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

1919
import (
20-
"context"
21-
"errors"
2220
"testing"
2321

2422
"github.com/stretchr/testify/require"
@@ -39,8 +37,7 @@ func TestCrossShardWorkspaceType(t *testing.T) {
3937
teamCluster = "logicalteamcluster"
4038
)
4139

42-
ctx, cancel := context.WithCancelCause(context.Background())
43-
defer cancel(errors.New("test has ended"))
40+
ctx := t.Context()
4441

4542
clusterIndex := index.New(nil)
4643
authIndex := NewIndex(ctx, nil)

pkg/virtual/framework/forwardingregistry/rest_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ func newStorage(t *testing.T, clusterClient kcpdynamic.ClusterInterface, apiExpo
9292
}
9393
table, _ := tableconvertor.New(headers)
9494

95-
ctx, cancelFn := context.WithCancel(context.Background())
96-
t.Cleanup(cancelFn)
95+
ctx := t.Context()
9796

9897
return forwardingregistry.NewStorage(
9998
ctx,

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

0 commit comments

Comments
 (0)