Skip to content

Commit fa055bd

Browse files
committed
use t.Context() in tests
On-behalf-of: @SAP [email protected]
1 parent 377ed2c commit fa055bd

File tree

8 files changed

+24
-27
lines changed

8 files changed

+24
-27
lines changed

internal/sync/context_test.go

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

1919
import (
20-
"context"
2120
"testing"
2221

2322
"github.com/kcp-dev/logicalcluster/v3"
@@ -27,9 +26,9 @@ import (
2726

2827
func TestNewContext(t *testing.T) {
2928
clusterName := logicalcluster.Name("foo")
30-
ctx := kontext.WithCluster(context.Background(), clusterName)
29+
ctx := kontext.WithCluster(t.Context(), clusterName)
3130

32-
combinedCtx := NewContext(context.Background(), ctx)
31+
combinedCtx := NewContext(t.Context(), ctx)
3332

3433
if combinedCtx.clusterName != clusterName {
3534
t.Fatalf("Expected function to recognize the cluster name in the context, but got %q", combinedCtx.clusterName)

internal/sync/state_store_test.go

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

1919
import (
20-
"context"
2120
"testing"
2221

2322
dummyv1alpha1 "github.com/kcp-dev/api-syncagent/internal/sync/apis/dummy/v1alpha1"
@@ -37,7 +36,7 @@ func TestStateStoreBasics(t *testing.T) {
3736
}, withKind("RemoteThing"))
3837

3938
serviceClusterClient := buildFakeClient()
40-
ctx := context.Background()
39+
ctx := t.Context()
4140
stateNamespace := "kcp-system"
4241

4342
primaryObjectSide := syncSide{

internal/sync/syncer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ func TestSyncerProcessingSingleResourceWithoutStatus(t *testing.T) {
907907
t.Fatalf("Failed to create syncer: %v", err)
908908
}
909909

910-
localCtx := context.Background()
910+
localCtx := t.Context()
911911
remoteCtx := kontext.WithCluster(localCtx, clusterName)
912912
ctx := NewContext(localCtx, remoteCtx)
913913

@@ -1213,7 +1213,7 @@ func TestSyncerProcessingSingleResourceWithStatus(t *testing.T) {
12131213
t.Fatalf("Failed to create syncer: %v", err)
12141214
}
12151215

1216-
localCtx := context.Background()
1216+
localCtx := t.Context()
12171217
remoteCtx := kontext.WithCluster(localCtx, clusterName)
12181218
ctx := NewContext(localCtx, remoteCtx)
12191219

test/e2e/apiexport/apiexport_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestPermissionsClaims(t *testing.T) {
4545
apiExportName = "kcp.example.com"
4646
)
4747

48-
ctx := context.Background()
48+
ctx := t.Context()
4949
ctrlruntime.SetLogger(logr.Discard())
5050

5151
// setup a test environment in kcp
@@ -247,7 +247,7 @@ func TestExistingPermissionsClaimsAreKept(t *testing.T) {
247247
apiExportName = "kcp.example.com"
248248
)
249249

250-
ctx := context.Background()
250+
ctx := t.Context()
251251
ctrlruntime.SetLogger(logr.Discard())
252252

253253
// setup a test environment in kcp
@@ -367,7 +367,7 @@ func TestSchemasAreMerged(t *testing.T) {
367367
apiExportName = "kcp.example.com"
368368
)
369369

370-
ctx := context.Background()
370+
ctx := t.Context()
371371
ctrlruntime.SetLogger(logr.Discard())
372372

373373
// setup a test environment in kcp
@@ -476,7 +476,7 @@ func TestSchemaIsKeptWhenDeletingPublishedResource(t *testing.T) {
476476
apiExportName = "kcp.example.com"
477477
)
478478

479-
ctx := context.Background()
479+
ctx := t.Context()
480480
ctrlruntime.SetLogger(logr.Discard())
481481

482482
// setup a test environment in kcp
@@ -614,7 +614,7 @@ func TestNewSchemasAreCreatedAsNeeded(t *testing.T) {
614614
apiExportName = "kcp.example.com"
615615
)
616616

617-
ctx := context.Background()
617+
ctx := t.Context()
618618
ctrlruntime.SetLogger(logr.Discard())
619619

620620
// setup a test environment in kcp

test/e2e/apiresourceschema/apiresourceschema_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestARSAreCreated(t *testing.T) {
4545
apiExportName = "example.com"
4646
)
4747

48-
ctx := context.Background()
48+
ctx := t.Context()
4949
ctrlruntime.SetLogger(logr.Discard())
5050

5151
// setup a test environment in kcp
@@ -116,7 +116,7 @@ func TestARSAreNotUpdated(t *testing.T) {
116116
apiExportName = "example.com"
117117
)
118118

119-
ctx := context.Background()
119+
ctx := t.Context()
120120
ctrlruntime.SetLogger(logr.Discard())
121121

122122
// setup a test environment in kcp
@@ -214,7 +214,7 @@ func TestARSOnlyContainsSelectedCRDVersion(t *testing.T) {
214214
theVersion = "v1"
215215
)
216216

217-
ctx := context.Background()
217+
ctx := t.Context()
218218
ctrlruntime.SetLogger(logr.Discard())
219219

220220
// setup a test environment in kcp
@@ -296,7 +296,7 @@ func TestMultiVersionCRD(t *testing.T) {
296296
// force a non-standard order, because it should not matter for the sync
297297
var selectedVersions = []string{"v2", "v1"}
298298

299-
ctx := context.Background()
299+
ctx := t.Context()
300300
ctrlruntime.SetLogger(logr.Discard())
301301

302302
// setup a test environment in kcp
@@ -386,7 +386,7 @@ func TestProjection(t *testing.T) {
386386
originalVersion = "v1"
387387
)
388388

389-
ctx := context.Background()
389+
ctx := t.Context()
390390
ctrlruntime.SetLogger(logr.Discard())
391391

392392
// setup a test environment in kcp
@@ -489,7 +489,7 @@ func TestNonCRDResource(t *testing.T) {
489489
originalVersion = "v1"
490490
)
491491

492-
ctx := context.Background()
492+
ctx := t.Context()
493493
ctrlruntime.SetLogger(logr.Discard())
494494

495495
// setup a test environment in kcp

test/e2e/discovery/discovery_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ limitations under the License.
1919
package discovery
2020

2121
import (
22-
"context"
2322
"testing"
2423

2524
"github.com/go-logr/logr"
@@ -95,7 +94,7 @@ func TestDiscoverSingleVersionCRD(t *testing.T) {
9594

9695
for _, testcase := range testcases {
9796
t.Run(testcase.name, func(t *testing.T) {
98-
ctx := context.Background()
97+
ctx := t.Context()
9998
ctrlruntime.SetLogger(logr.Discard())
10099

101100
kubeconfigFile, _, _ := utils.RunEnvtest(t, testcase.crdFiles)

test/e2e/sync/primary_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestSyncSimpleObject(t *testing.T) {
5353
orgWorkspace = "sync-simple"
5454
)
5555

56-
ctx := context.Background()
56+
ctx := t.Context()
5757
ctrlruntime.SetLogger(logr.Discard())
5858

5959
// setup a test environment in kcp
@@ -143,7 +143,7 @@ func TestSyncSimpleObjectOldNaming(t *testing.T) {
143143
orgWorkspace = "sync-simple-deprecated"
144144
)
145145

146-
ctx := context.Background()
146+
ctx := t.Context()
147147
ctrlruntime.SetLogger(logr.Discard())
148148

149149
// setup a test environment in kcp
@@ -232,7 +232,7 @@ func TestSyncWithDefaultNamingRules(t *testing.T) {
232232
orgWorkspace = "sync-default-naming-rules"
233233
)
234234

235-
ctx := context.Background()
235+
ctx := t.Context()
236236
ctrlruntime.SetLogger(logr.Discard())
237237

238238
// setup a test environment in kcp
@@ -327,7 +327,7 @@ func TestLocalChangesAreKept(t *testing.T) {
327327
orgWorkspace = "sync-undo-local-changes"
328328
)
329329

330-
ctx := context.Background()
330+
ctx := t.Context()
331331
ctrlruntime.SetLogger(logr.Discard())
332332

333333
// setup a test environment in kcp
@@ -533,7 +533,7 @@ func TestResourceFilter(t *testing.T) {
533533
orgWorkspace = "sync-resource-filter"
534534
)
535535

536-
ctx := context.Background()
536+
ctx := t.Context()
537537
ctrlruntime.SetLogger(logr.Discard())
538538

539539
// setup a test environment in kcp
@@ -654,7 +654,7 @@ func TestSyncingOverlyLongNames(t *testing.T) {
654654
orgWorkspace = "sync-long-names"
655655
)
656656

657-
ctx := context.Background()
657+
ctx := t.Context()
658658
ctrlruntime.SetLogger(logr.Discard())
659659

660660
// setup a test environment in kcp

test/e2e/sync/related_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ func TestSyncRelatedObjects(t *testing.T) {
457457

458458
for _, testcase := range testcases {
459459
t.Run(testcase.name, func(t *testing.T) {
460-
ctx := context.Background()
460+
ctx := t.Context()
461461

462462
// setup a test environment in kcp
463463
orgKubconfig := utils.CreateOrganization(t, ctx, testcase.workspace, apiExportName)

0 commit comments

Comments
 (0)