Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions internal/controller/nginx/agent/broadcast/broadcast_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package broadcast_test

import (
"context"
"testing"

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

broadcaster := broadcast.NewDeploymentBroadcaster(context.Background(), stopCh)
broadcaster := broadcast.NewDeploymentBroadcaster(t.Context(), stopCh)

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

broadcaster := broadcast.NewDeploymentBroadcaster(context.Background(), stopCh)
broadcaster := broadcast.NewDeploymentBroadcaster(t.Context(), stopCh)

subscriber1 := broadcaster.Subscribe()
subscriber2 := broadcaster.Subscribe()
Expand Down Expand Up @@ -70,7 +69,7 @@ func TestSubscribe_NoListeners(t *testing.T) {
stopCh := make(chan struct{})
defer close(stopCh)

broadcaster := broadcast.NewDeploymentBroadcaster(context.Background(), stopCh)
broadcaster := broadcast.NewDeploymentBroadcaster(t.Context(), stopCh)

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

broadcaster := broadcast.NewDeploymentBroadcaster(context.Background(), stopCh)
broadcaster := broadcast.NewDeploymentBroadcaster(t.Context(), stopCh)

subscriber := broadcaster.Subscribe()

Expand Down
37 changes: 19 additions & 18 deletions internal/controller/nginx/agent/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ func createFakeK8sClient(initObjs ...runtime.Object) (client.Client, error) {
return fakeClient, nil
}

func createGrpcContext() context.Context {
return grpcContext.NewGrpcContext(context.Background(), grpcContext.GrpcInfo{
func createGrpcContext(t *testing.T) context.Context {
t.Helper()
return grpcContext.NewGrpcContext(t.Context(), grpcContext.GrpcInfo{
UUID: "1234567",
})
}

func createGrpcContextWithCancel() (context.Context, context.CancelFunc) {
ctx, cancel := context.WithCancel(context.Background())

func createGrpcContextWithCancel(t *testing.T) (context.Context, context.CancelFunc) {
t.Helper()
ctx, cancel := context.WithCancel(t.Context())
return grpcContext.NewGrpcContext(ctx, grpcContext.GrpcInfo{
UUID: "1234567",
}), cancel
Expand Down Expand Up @@ -122,7 +123,7 @@ func TestCreateConnection(t *testing.T) {
}{
{
name: "successfully tracks a connection",
ctx: createGrpcContext(),
ctx: createGrpcContext(t),
request: &pb.CreateConnectionRequest{
Resource: &pb.Resource{
Info: &pb.Resource_ContainerInfo{
Expand Down Expand Up @@ -181,14 +182,14 @@ func TestCreateConnection(t *testing.T) {
},
{
name: "context is missing data",
ctx: context.Background(),
ctx: t.Context(),
request: &pb.CreateConnectionRequest{},
response: nil,
errString: agentgrpc.ErrStatusInvalidConnection.Error(),
},
{
name: "error getting pod owner",
ctx: createGrpcContext(),
ctx: createGrpcContext(t),
request: &pb.CreateConnectionRequest{
Resource: &pb.Resource{
Info: &pb.Resource_ContainerInfo{
Expand Down Expand Up @@ -360,7 +361,7 @@ func TestSubscribe(t *testing.T) {
}
deployment.SetNGINXPlusActions([]*pb.NGINXPlusAction{initialAction})

ctx, cancel := createGrpcContextWithCancel()
ctx, cancel := createGrpcContextWithCancel(t)
defer cancel()

mockServer := newMockSubscribeServer(ctx)
Expand Down Expand Up @@ -501,7 +502,7 @@ func TestSubscribe_Reset(t *testing.T) {
deployment.SetFiles(files, []v1.VolumeMount{})
deployment.SetImageVersion("nginx:v1.0.0")

ctx, cancel := createGrpcContextWithCancel()
ctx, cancel := createGrpcContextWithCancel(t)
defer cancel()

mockServer := newMockSubscribeServer(ctx)
Expand Down Expand Up @@ -542,7 +543,7 @@ func TestSubscribe_Errors(t *testing.T) {
}{
{
name: "context is missing data",
ctx: context.Background(),
ctx: t.Context(),
errString: agentgrpc.ErrStatusInvalidConnection.Error(),
},
{
Expand Down Expand Up @@ -594,7 +595,7 @@ func TestSubscribe_Errors(t *testing.T) {
if test.ctx != nil {
ctx = test.ctx
} else {
ctx, cancel = createGrpcContextWithCancel()
ctx, cancel = createGrpcContextWithCancel(t)
defer cancel()
}

Expand Down Expand Up @@ -723,7 +724,7 @@ func TestSetInitialConfig_Errors(t *testing.T) {
test.setup(msgr, deployment)
}

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

g.Expect(err).To(HaveOccurred())
g.Expect(err.Error()).To(ContainSubstring(test.errString))
Expand All @@ -744,7 +745,7 @@ func TestUpdateDataPlaneStatus(t *testing.T) {
}{
{
name: "successfully sets the status",
ctx: createGrpcContext(),
ctx: createGrpcContext(t),
request: &pb.UpdateDataPlaneStatusRequest{
Resource: &pb.Resource{
Instances: []*pb.Instance{
Expand All @@ -762,7 +763,7 @@ func TestUpdateDataPlaneStatus(t *testing.T) {
},
{
name: "successfully sets the status using plus",
ctx: createGrpcContext(),
ctx: createGrpcContext(t),
request: &pb.UpdateDataPlaneStatusRequest{
Resource: &pb.Resource{
Instances: []*pb.Instance{
Expand All @@ -786,14 +787,14 @@ func TestUpdateDataPlaneStatus(t *testing.T) {
},
{
name: "context is missing data",
ctx: context.Background(),
ctx: t.Context(),
request: &pb.UpdateDataPlaneStatusRequest{},
response: nil,
errString: agentgrpc.ErrStatusInvalidConnection.Error(),
},
{
name: "request does not contain ID",
ctx: createGrpcContext(),
ctx: createGrpcContext(t),
request: &pb.UpdateDataPlaneStatusRequest{},
response: nil,
errString: "request does not contain nginx instanceID",
Expand Down Expand Up @@ -855,7 +856,7 @@ func TestUpdateDataPlaneHealth(t *testing.T) {
nil,
)

resp, err := cs.UpdateDataPlaneHealth(context.Background(), &pb.UpdateDataPlaneHealthRequest{})
resp, err := cs.UpdateDataPlaneHealth(t.Context(), &pb.UpdateDataPlaneHealthRequest{})

g.Expect(err).ToNot(HaveOccurred())
g.Expect(resp).To(Equal(&pb.UpdateDataPlaneHealthResponse{}))
Expand Down
5 changes: 2 additions & 3 deletions internal/controller/nginx/agent/deployment_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package agent

import (
"context"
"errors"
"testing"

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

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

deployment := store.GetOrStore(context.Background(), nsName, nil)
deployment := store.GetOrStore(t.Context(), nsName, nil)
g.Expect(deployment).ToNot(BeNil())

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

deployment = store.GetOrStore(context.Background(), nsName, nil)
deployment = store.GetOrStore(t.Context(), nsName, nil)
g.Expect(fetchedDeployment).To(Equal(deployment))

store.Remove(nsName)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package grpcinfo_test

import (
"context"
"testing"

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

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

newCtx := grpcContext.NewGrpcContext(context.Background(), grpcInfo)
newCtx := grpcContext.NewGrpcContext(t.Context(), grpcInfo)
info, ok := grpcContext.FromContext(newCtx)
g.Expect(ok).To(BeTrue())
g.Expect(info).To(Equal(grpcInfo))
Expand All @@ -25,7 +24,7 @@ func TestGrpcInfoNotInContext(t *testing.T) {
t.Parallel()
g := NewWithT(t)

info, ok := grpcContext.FromContext(context.Background())
info, ok := grpcContext.FromContext(t.Context())
g.Expect(ok).To(BeFalse())
g.Expect(info).To(Equal(grpcContext.GrpcInfo{}))
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestSend(t *testing.T) {
t.Parallel()
g := NewWithT(t)

ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(t.Context())
defer cancel()

server := createServer()
Expand All @@ -90,7 +90,7 @@ func TestMessages(t *testing.T) {
t.Parallel()
g := NewWithT(t)

ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(t.Context())
defer cancel()

server := createServer()
Expand All @@ -108,7 +108,7 @@ func TestErrors(t *testing.T) {
t.Parallel()
g := NewWithT(t)

ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(t.Context())
defer cancel()

server := createErrorServer()
Expand Down
5 changes: 2 additions & 3 deletions internal/controller/provisioner/handler_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package provisioner

import (
"context"
"testing"

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

ctx := context.TODO()
ctx := t.Context()
logger := logr.Discard()

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

ctx := context.TODO()
ctx := t.Context()
logger := logr.Discard()

// initialize resources
Expand Down
Loading
Loading