Skip to content

Commit 4c96b71

Browse files
committed
rebase main, fix conflict
1 parent f2ebf93 commit 4c96b71

File tree

16 files changed

+123
-129
lines changed

16 files changed

+123
-129
lines changed

internal/controller/nginx/agent/broadcast/broadcast_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package broadcast_test
22

33
import (
4-
"context"
54
"testing"
65

76
. "github.com/onsi/gomega"
@@ -16,7 +15,7 @@ func TestSubscribe(t *testing.T) {
1615
stopCh := make(chan struct{})
1716
defer close(stopCh)
1817

19-
broadcaster := broadcast.NewDeploymentBroadcaster(context.Background(), stopCh)
18+
broadcaster := broadcast.NewDeploymentBroadcaster(t.Context(), stopCh)
2019

2120
subscriber := broadcaster.Subscribe()
2221
g.Expect(subscriber.ID).NotTo(BeEmpty())
@@ -41,7 +40,7 @@ func TestSubscribe_MultipleListeners(t *testing.T) {
4140
stopCh := make(chan struct{})
4241
defer close(stopCh)
4342

44-
broadcaster := broadcast.NewDeploymentBroadcaster(context.Background(), stopCh)
43+
broadcaster := broadcast.NewDeploymentBroadcaster(t.Context(), stopCh)
4544

4645
subscriber1 := broadcaster.Subscribe()
4746
subscriber2 := broadcaster.Subscribe()
@@ -70,7 +69,7 @@ func TestSubscribe_NoListeners(t *testing.T) {
7069
stopCh := make(chan struct{})
7170
defer close(stopCh)
7271

73-
broadcaster := broadcast.NewDeploymentBroadcaster(context.Background(), stopCh)
72+
broadcaster := broadcast.NewDeploymentBroadcaster(t.Context(), stopCh)
7473

7574
message := broadcast.NginxAgentMessage{
7675
ConfigVersion: "v1",
@@ -88,7 +87,7 @@ func TestCancelSubscription(t *testing.T) {
8887
stopCh := make(chan struct{})
8988
defer close(stopCh)
9089

91-
broadcaster := broadcast.NewDeploymentBroadcaster(context.Background(), stopCh)
90+
broadcaster := broadcast.NewDeploymentBroadcaster(t.Context(), stopCh)
9291

9392
subscriber := broadcaster.Subscribe()
9493

internal/controller/nginx/agent/command_test.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,16 @@ func createFakeK8sClient(initObjs ...runtime.Object) (client.Client, error) {
7373
return fakeClient, nil
7474
}
7575

76-
func createGrpcContext() context.Context {
77-
return grpcContext.NewGrpcContext(context.Background(), grpcContext.GrpcInfo{
76+
func createGrpcContext(t *testing.T) context.Context {
77+
t.Helper()
78+
return grpcContext.NewGrpcContext(t.Context(), grpcContext.GrpcInfo{
7879
UUID: "1234567",
7980
})
8081
}
8182

82-
func createGrpcContextWithCancel() (context.Context, context.CancelFunc) {
83-
ctx, cancel := context.WithCancel(context.Background())
83+
func createGrpcContextWithCancel(t *testing.T) (context.Context, context.CancelFunc) {
84+
t.Helper()
85+
ctx, cancel := context.WithCancel(t.Context())
8486

8587
return grpcContext.NewGrpcContext(ctx, grpcContext.GrpcInfo{
8688
UUID: "1234567",
@@ -122,7 +124,7 @@ func TestCreateConnection(t *testing.T) {
122124
}{
123125
{
124126
name: "successfully tracks a connection",
125-
ctx: createGrpcContext(),
127+
ctx: createGrpcContext(t),
126128
request: &pb.CreateConnectionRequest{
127129
Resource: &pb.Resource{
128130
Info: &pb.Resource_ContainerInfo{
@@ -181,14 +183,14 @@ func TestCreateConnection(t *testing.T) {
181183
},
182184
{
183185
name: "context is missing data",
184-
ctx: context.Background(),
186+
ctx: t.Context(),
185187
request: &pb.CreateConnectionRequest{},
186188
response: nil,
187189
errString: agentgrpc.ErrStatusInvalidConnection.Error(),
188190
},
189191
{
190192
name: "error getting pod owner",
191-
ctx: createGrpcContext(),
193+
ctx: createGrpcContext(t),
192194
request: &pb.CreateConnectionRequest{
193195
Resource: &pb.Resource{
194196
Info: &pb.Resource_ContainerInfo{
@@ -360,7 +362,7 @@ func TestSubscribe(t *testing.T) {
360362
}
361363
deployment.SetNGINXPlusActions([]*pb.NGINXPlusAction{initialAction})
362364

363-
ctx, cancel := createGrpcContextWithCancel()
365+
ctx, cancel := createGrpcContextWithCancel(t)
364366
defer cancel()
365367

366368
mockServer := newMockSubscribeServer(ctx)
@@ -501,7 +503,7 @@ func TestSubscribe_Reset(t *testing.T) {
501503
deployment.SetFiles(files, []v1.VolumeMount{})
502504
deployment.SetImageVersion("nginx:v1.0.0")
503505

504-
ctx, cancel := createGrpcContextWithCancel()
506+
ctx, cancel := createGrpcContextWithCancel(t)
505507
defer cancel()
506508

507509
mockServer := newMockSubscribeServer(ctx)
@@ -542,7 +544,7 @@ func TestSubscribe_Errors(t *testing.T) {
542544
}{
543545
{
544546
name: "context is missing data",
545-
ctx: context.Background(),
547+
ctx: t.Context(),
546548
errString: agentgrpc.ErrStatusInvalidConnection.Error(),
547549
},
548550
{
@@ -594,7 +596,7 @@ func TestSubscribe_Errors(t *testing.T) {
594596
if test.ctx != nil {
595597
ctx = test.ctx
596598
} else {
597-
ctx, cancel = createGrpcContextWithCancel()
599+
ctx, cancel = createGrpcContextWithCancel(t)
598600
defer cancel()
599601
}
600602

@@ -723,7 +725,7 @@ func TestSetInitialConfig_Errors(t *testing.T) {
723725
test.setup(msgr, deployment)
724726
}
725727

726-
err = cs.setInitialConfig(context.Background(), &grpcContext.GrpcInfo{}, deployment, conn, msgr)
728+
err = cs.setInitialConfig(t.Context(), &grpcContext.GrpcInfo{}, deployment, conn, msgr)
727729

728730
g.Expect(err).To(HaveOccurred())
729731
g.Expect(err.Error()).To(ContainSubstring(test.errString))
@@ -744,7 +746,7 @@ func TestUpdateDataPlaneStatus(t *testing.T) {
744746
}{
745747
{
746748
name: "successfully sets the status",
747-
ctx: createGrpcContext(),
749+
ctx: createGrpcContext(t),
748750
request: &pb.UpdateDataPlaneStatusRequest{
749751
Resource: &pb.Resource{
750752
Instances: []*pb.Instance{
@@ -762,7 +764,7 @@ func TestUpdateDataPlaneStatus(t *testing.T) {
762764
},
763765
{
764766
name: "successfully sets the status using plus",
765-
ctx: createGrpcContext(),
767+
ctx: createGrpcContext(t),
766768
request: &pb.UpdateDataPlaneStatusRequest{
767769
Resource: &pb.Resource{
768770
Instances: []*pb.Instance{
@@ -786,14 +788,14 @@ func TestUpdateDataPlaneStatus(t *testing.T) {
786788
},
787789
{
788790
name: "context is missing data",
789-
ctx: context.Background(),
791+
ctx: t.Context(),
790792
request: &pb.UpdateDataPlaneStatusRequest{},
791793
response: nil,
792794
errString: agentgrpc.ErrStatusInvalidConnection.Error(),
793795
},
794796
{
795797
name: "request does not contain ID",
796-
ctx: createGrpcContext(),
798+
ctx: createGrpcContext(t),
797799
request: &pb.UpdateDataPlaneStatusRequest{},
798800
response: nil,
799801
errString: "request does not contain nginx instanceID",
@@ -855,7 +857,7 @@ func TestUpdateDataPlaneHealth(t *testing.T) {
855857
nil,
856858
)
857859

858-
resp, err := cs.UpdateDataPlaneHealth(context.Background(), &pb.UpdateDataPlaneHealthRequest{})
860+
resp, err := cs.UpdateDataPlaneHealth(t.Context(), &pb.UpdateDataPlaneHealthRequest{})
859861

860862
g.Expect(err).ToNot(HaveOccurred())
861863
g.Expect(resp).To(Equal(&pb.UpdateDataPlaneHealthResponse{}))

internal/controller/nginx/agent/deployment_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package agent
22

33
import (
4-
"context"
54
"errors"
65
"testing"
76

@@ -218,13 +217,13 @@ func TestDeploymentStore(t *testing.T) {
218217

219218
nsName := types.NamespacedName{Namespace: "default", Name: "test-deployment"}
220219

221-
deployment := store.GetOrStore(context.Background(), nsName, nil)
220+
deployment := store.GetOrStore(t.Context(), nsName, nil)
222221
g.Expect(deployment).ToNot(BeNil())
223222

224223
fetchedDeployment := store.Get(nsName)
225224
g.Expect(fetchedDeployment).To(Equal(deployment))
226225

227-
deployment = store.GetOrStore(context.Background(), nsName, nil)
226+
deployment = store.GetOrStore(t.Context(), nsName, nil)
228227
g.Expect(fetchedDeployment).To(Equal(deployment))
229228

230229
store.Remove(nsName)

internal/controller/nginx/agent/grpc/context/context_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package grpcinfo_test
22

33
import (
4-
"context"
54
"testing"
65

76
. "github.com/onsi/gomega"
@@ -15,7 +14,7 @@ func TestGrpcInfoInContext(t *testing.T) {
1514

1615
grpcInfo := grpcContext.GrpcInfo{Token: "test"}
1716

18-
newCtx := grpcContext.NewGrpcContext(context.Background(), grpcInfo)
17+
newCtx := grpcContext.NewGrpcContext(t.Context(), grpcInfo)
1918
info, ok := grpcContext.FromContext(newCtx)
2019
g.Expect(ok).To(BeTrue())
2120
g.Expect(info).To(Equal(grpcInfo))
@@ -25,7 +24,7 @@ func TestGrpcInfoNotInContext(t *testing.T) {
2524
t.Parallel()
2625
g := NewWithT(t)
2726

28-
info, ok := grpcContext.FromContext(context.Background())
27+
info, ok := grpcContext.FromContext(t.Context())
2928
g.Expect(ok).To(BeFalse())
3029
g.Expect(info).To(Equal(grpcContext.GrpcInfo{}))
3130
}

internal/controller/nginx/agent/grpc/messenger/messenger_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestSend(t *testing.T) {
6464
t.Parallel()
6565
g := NewWithT(t)
6666

67-
ctx, cancel := context.WithCancel(context.Background())
67+
ctx, cancel := context.WithCancel(t.Context())
6868
defer cancel()
6969

7070
server := createServer()
@@ -90,7 +90,7 @@ func TestMessages(t *testing.T) {
9090
t.Parallel()
9191
g := NewWithT(t)
9292

93-
ctx, cancel := context.WithCancel(context.Background())
93+
ctx, cancel := context.WithCancel(t.Context())
9494
defer cancel()
9595

9696
server := createServer()
@@ -108,7 +108,7 @@ func TestErrors(t *testing.T) {
108108
t.Parallel()
109109
g := NewWithT(t)
110110

111-
ctx, cancel := context.WithCancel(context.Background())
111+
ctx, cancel := context.WithCancel(t.Context())
112112
defer cancel()
113113

114114
server := createErrorServer()

internal/controller/provisioner/handler_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package provisioner
22

33
import (
4-
"context"
54
"testing"
65

76
"github.com/go-logr/logr"
@@ -35,7 +34,7 @@ func TestHandleEventBatch_Upsert(t *testing.T) {
3534
handler, err := newEventHandler(store, provisioner, labelSelector, gcName)
3635
g.Expect(err).ToNot(HaveOccurred())
3736

38-
ctx := context.TODO()
37+
ctx := t.Context()
3938
logger := logr.Discard()
4039

4140
gateway := &gatewayv1.Gateway{
@@ -226,7 +225,7 @@ func TestHandleEventBatch_Delete(t *testing.T) {
226225
handler, err := newEventHandler(store, provisioner, labelSelector, gcName)
227226
g.Expect(err).ToNot(HaveOccurred())
228227

229-
ctx := context.TODO()
228+
ctx := t.Context()
230229
logger := logr.Discard()
231230

232231
// initialize resources

0 commit comments

Comments
 (0)