@@ -73,15 +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 () )
84-
83+ func createGrpcContextWithCancel (t * testing. T ) (context.Context , context.CancelFunc ) {
84+ t . Helper ( )
85+ ctx , cancel := context . WithCancel ( t . Context ())
8586 return grpcContext .NewGrpcContext (ctx , grpcContext.GrpcInfo {
8687 UUID : "1234567" ,
8788 }), cancel
@@ -122,7 +123,7 @@ func TestCreateConnection(t *testing.T) {
122123 }{
123124 {
124125 name : "successfully tracks a connection" ,
125- ctx : createGrpcContext (),
126+ ctx : createGrpcContext (t ),
126127 request : & pb.CreateConnectionRequest {
127128 Resource : & pb.Resource {
128129 Info : & pb.Resource_ContainerInfo {
@@ -181,14 +182,14 @@ func TestCreateConnection(t *testing.T) {
181182 },
182183 {
183184 name : "context is missing data" ,
184- ctx : context . Background (),
185+ ctx : t . Context (),
185186 request : & pb.CreateConnectionRequest {},
186187 response : nil ,
187188 errString : agentgrpc .ErrStatusInvalidConnection .Error (),
188189 },
189190 {
190191 name : "error getting pod owner" ,
191- ctx : createGrpcContext (),
192+ ctx : createGrpcContext (t ),
192193 request : & pb.CreateConnectionRequest {
193194 Resource : & pb.Resource {
194195 Info : & pb.Resource_ContainerInfo {
@@ -360,7 +361,7 @@ func TestSubscribe(t *testing.T) {
360361 }
361362 deployment .SetNGINXPlusActions ([]* pb.NGINXPlusAction {initialAction })
362363
363- ctx , cancel := createGrpcContextWithCancel ()
364+ ctx , cancel := createGrpcContextWithCancel (t )
364365 defer cancel ()
365366
366367 mockServer := newMockSubscribeServer (ctx )
@@ -501,7 +502,7 @@ func TestSubscribe_Reset(t *testing.T) {
501502 deployment .SetFiles (files , []v1.VolumeMount {})
502503 deployment .SetImageVersion ("nginx:v1.0.0" )
503504
504- ctx , cancel := createGrpcContextWithCancel ()
505+ ctx , cancel := createGrpcContextWithCancel (t )
505506 defer cancel ()
506507
507508 mockServer := newMockSubscribeServer (ctx )
@@ -542,7 +543,7 @@ func TestSubscribe_Errors(t *testing.T) {
542543 }{
543544 {
544545 name : "context is missing data" ,
545- ctx : context . Background (),
546+ ctx : t . Context (),
546547 errString : agentgrpc .ErrStatusInvalidConnection .Error (),
547548 },
548549 {
@@ -594,7 +595,7 @@ func TestSubscribe_Errors(t *testing.T) {
594595 if test .ctx != nil {
595596 ctx = test .ctx
596597 } else {
597- ctx , cancel = createGrpcContextWithCancel ()
598+ ctx , cancel = createGrpcContextWithCancel (t )
598599 defer cancel ()
599600 }
600601
@@ -723,7 +724,7 @@ func TestSetInitialConfig_Errors(t *testing.T) {
723724 test .setup (msgr , deployment )
724725 }
725726
726- err = cs .setInitialConfig (context . Background (), & grpcContext.GrpcInfo {}, deployment , conn , msgr )
727+ err = cs .setInitialConfig (t . Context (), & grpcContext.GrpcInfo {}, deployment , conn , msgr )
727728
728729 g .Expect (err ).To (HaveOccurred ())
729730 g .Expect (err .Error ()).To (ContainSubstring (test .errString ))
@@ -744,7 +745,7 @@ func TestUpdateDataPlaneStatus(t *testing.T) {
744745 }{
745746 {
746747 name : "successfully sets the status" ,
747- ctx : createGrpcContext (),
748+ ctx : createGrpcContext (t ),
748749 request : & pb.UpdateDataPlaneStatusRequest {
749750 Resource : & pb.Resource {
750751 Instances : []* pb.Instance {
@@ -762,7 +763,7 @@ func TestUpdateDataPlaneStatus(t *testing.T) {
762763 },
763764 {
764765 name : "successfully sets the status using plus" ,
765- ctx : createGrpcContext (),
766+ ctx : createGrpcContext (t ),
766767 request : & pb.UpdateDataPlaneStatusRequest {
767768 Resource : & pb.Resource {
768769 Instances : []* pb.Instance {
@@ -786,14 +787,14 @@ func TestUpdateDataPlaneStatus(t *testing.T) {
786787 },
787788 {
788789 name : "context is missing data" ,
789- ctx : context . Background (),
790+ ctx : t . Context (),
790791 request : & pb.UpdateDataPlaneStatusRequest {},
791792 response : nil ,
792793 errString : agentgrpc .ErrStatusInvalidConnection .Error (),
793794 },
794795 {
795796 name : "request does not contain ID" ,
796- ctx : createGrpcContext (),
797+ ctx : createGrpcContext (t ),
797798 request : & pb.UpdateDataPlaneStatusRequest {},
798799 response : nil ,
799800 errString : "request does not contain nginx instanceID" ,
@@ -855,7 +856,7 @@ func TestUpdateDataPlaneHealth(t *testing.T) {
855856 nil ,
856857 )
857858
858- resp , err := cs .UpdateDataPlaneHealth (context . Background (), & pb.UpdateDataPlaneHealthRequest {})
859+ resp , err := cs .UpdateDataPlaneHealth (t . Context (), & pb.UpdateDataPlaneHealthRequest {})
859860
860861 g .Expect (err ).ToNot (HaveOccurred ())
861862 g .Expect (resp ).To (Equal (& pb.UpdateDataPlaneHealthResponse {}))
0 commit comments