@@ -353,7 +353,8 @@ func TestStartSyncHostNCVersionLoop(t *testing.T) {
353353 SyncHostNCVersionIntervalMs : 100 ,
354354 ChannelMode : orchestratorType ,
355355 }
356- svc .StartSyncHostNCVersionLoop (t .Context (), cnsconf )
356+ err := svc .StartSyncHostNCVersionLoop (t .Context (), cnsconf )
357+ assert .NoError (t , err )
357358 svc .Wait (t .Context ()) // wait for at leat one run
358359 containerStatus = svc .state .ContainerStatus [req .NetworkContainerid ]
359360 if containerStatus .HostVersion != "0" {
@@ -405,7 +406,8 @@ func TestPendingIPsGotUpdatedWhenSyncHostNCVersion(t *testing.T) {
405406 cleanup := setMockNMAgent (svc , mnma )
406407 defer cleanup ()
407408
408- svc .StartSyncHostNCVersionLoop (t .Context (), fastcnsconf )
409+ err := svc .StartSyncHostNCVersionLoop (t .Context (), fastcnsconf )
410+ assert .NoError (t , err )
409411 svc .Wait (t .Context ()) // wait for at leat one run
410412 containerStatus = svc .state .ContainerStatus [req .NetworkContainerid ]
411413
@@ -446,7 +448,7 @@ func TestSyncHostNCVersionErrorMissingNC(t *testing.T) {
446448 cleanup := setMockNMAgent (svc , mnma )
447449 defer cleanup ()
448450
449- _ , err := svc .syncHostNCVersion (context . Background (), cns .KubernetesCRD )
451+ _ , err := svc .syncHostNCVersion (t . Context (), cns .KubernetesCRD )
450452 if err == nil {
451453 t .Errorf ("Expected error when NC is missing from both NMAgent and IMDS, but got nil" )
452454 }
@@ -491,7 +493,7 @@ func TestSyncHostNCVersionLocalVersionHigher(t *testing.T) {
491493 cleanup := setMockNMAgent (svc , mnma )
492494 defer cleanup ()
493495
494- _ , err := svc .syncHostNCVersion (context . Background (), cns .KubernetesCRD )
496+ _ , err := svc .syncHostNCVersion (t . Context (), cns .KubernetesCRD )
495497 if err != nil {
496498 t .Errorf ("Expected sync to succeed, but got error: %v" , err )
497499 }
@@ -534,7 +536,7 @@ func TestSyncHostNCVersionLocalHigherThanDNC(t *testing.T) {
534536
535537 // This should detect that localNCVersion (3) > dncNCVersion (1) and log error
536538 // but since there are no outdated NCs, it should return successfully
537- _ , err := svc .syncHostNCVersion (context . Background (), cns .KubernetesCRD )
539+ _ , err := svc .syncHostNCVersion (t . Context (), cns .KubernetesCRD )
538540 if err != nil {
539541 t .Errorf ("Expected no error when localNCVersion > dncNCVersion (no outdated NCs), but got: %v" , err )
540542 }
@@ -607,7 +609,7 @@ func TestSyncHostNCVersionIMDSAPIVersionNotSupported(t *testing.T) {
607609 defer func () { svc .imdsClient = originalIMDS }()
608610
609611 // Test should fail because of outdated IMDS NC that can't be updated
610- _ , err := svc .syncHostNCVersion (context . Background (), orchestratorType )
612+ _ , err := svc .syncHostNCVersion (t . Context (), orchestratorType )
611613 if err == nil {
612614 t .Errorf ("Expected error when there are outdated IMDS NCs but API version is not supported, but got nil" )
613615 }
@@ -1391,9 +1393,10 @@ func TestCNIConflistGenerationNewNC(t *testing.T) {
13911393 imdsClient : fakes .NewMockIMDSClient (),
13921394 }
13931395
1394- ctx , cancel := context .WithTimeout (context . Background (), time .Second * 5 )
1396+ ctx , cancel := context .WithTimeout (t . Context (), time .Second * 5 )
13951397 defer cancel ()
1396- service .StartSyncHostNCVersionLoop (ctx , fastcnsconf )
1398+ err := service .StartSyncHostNCVersionLoop (ctx , fastcnsconf )
1399+ assert .NoError (t , err )
13971400 service .Wait (ctx )
13981401 assert .Equal (t , 1 , mockgen .getGeneratedCount ())
13991402}
@@ -1433,9 +1436,10 @@ func TestCNIConflistGenerationExistingNC(t *testing.T) {
14331436 imdsClient : fakes .NewMockIMDSClient (),
14341437 }
14351438
1436- ctx , cancel := context .WithTimeout (context . Background (), time .Second * 5 )
1439+ ctx , cancel := context .WithTimeout (t . Context (), time .Second * 5 )
14371440 defer cancel ()
1438- service .StartSyncHostNCVersionLoop (ctx , fastcnsconf )
1441+ err := service .StartSyncHostNCVersionLoop (ctx , fastcnsconf )
1442+ assert .NoError (t , err )
14391443 service .Wait (ctx )
14401444 assert .Equal (t , 1 , mockgen .getGeneratedCount ())
14411445}
@@ -1476,9 +1480,10 @@ func TestCNIConflistGenerationNewNCTwice(t *testing.T) {
14761480 imdsClient : fakes .NewMockIMDSClient (),
14771481 }
14781482
1479- ctx , cancel := context .WithTimeout (context . Background (), time .Second * 5 )
1483+ ctx , cancel := context .WithTimeout (t . Context (), time .Second * 5 )
14801484 defer cancel ()
1481- service .StartSyncHostNCVersionLoop (ctx , fastcnsconf )
1485+ err := service .StartSyncHostNCVersionLoop (ctx , fastcnsconf )
1486+ assert .NoError (t , err )
14821487 service .Wait (ctx )
14831488 assert .Equal (t , 1 , mockgen .getGeneratedCount ())
14841489 // CNI conflist gen happens in goroutine so sleep for a second to let it run
@@ -1514,9 +1519,10 @@ func TestCNIConflistNotGenerated(t *testing.T) {
15141519 imdsClient : fakes .NewMockIMDSClient (),
15151520 }
15161521
1517- ctx , cancel := context .WithTimeout (context . Background (), time .Second * 5 )
1522+ ctx , cancel := context .WithTimeout (t . Context (), time .Second * 5 )
15181523 defer cancel ()
1519- service .StartSyncHostNCVersionLoop (ctx , fastcnsconf )
1524+ err := service .StartSyncHostNCVersionLoop (ctx , fastcnsconf )
1525+ assert .NoError (t , err )
15201526 service .Wait (ctx )
15211527 assert .Equal (t , 0 , mockgen .getGeneratedCount ())
15221528}
@@ -1558,9 +1564,10 @@ func TestCNIConflistGenerationOnNMAError(t *testing.T) {
15581564 imdsClient : fakes .NewMockIMDSClient (),
15591565 }
15601566
1561- ctx , cancel := context .WithTimeout (context . Background (), time .Second * 5 )
1567+ ctx , cancel := context .WithTimeout (t . Context (), time .Second * 5 )
15621568 defer cancel ()
1563- service .StartSyncHostNCVersionLoop (ctx , fastcnsconf )
1569+ err := service .StartSyncHostNCVersionLoop (ctx , fastcnsconf )
1570+ assert .NoError (t , err )
15641571 service .Wait (ctx )
15651572 assert .Equal (t , 1 , mockgen .getGeneratedCount ())
15661573}
0 commit comments