@@ -83,20 +83,11 @@ func TestContainerWithHostNetworkOptions(t *testing.T) {
8383 CleanupContainer (t , nginxC )
8484 require .NoError (t , err )
8585
86- // host, err := nginxC.Host(ctx)
87- // if err != nil {
88- // t.Errorf("Expected host %s. Got '%d'.", host, err)
89- // }
90- //
9186 endpoint , err := nginxC .PortEndpoint (ctx , nginxHighPort , "http" )
92- if err != nil {
93- t .Errorf ("Expected server endpoint. Got '%v'." , err )
94- }
87+ require .NoErrorf (t , err , "Expected server endpoint" )
9588
9689 _ , err = http .Get (endpoint )
97- if err != nil {
98- t .Errorf ("Expected OK response. Got '%d'." , err )
99- }
90+ require .NoErrorf (t , err , "Expected OK response" )
10091}
10192
10293func TestContainerWithHostNetworkOptions_UseExposePortsFromImageConfigs (t * testing.T ) {
@@ -115,17 +106,13 @@ func TestContainerWithHostNetworkOptions_UseExposePortsFromImageConfigs(t *testi
115106 require .NoError (t , err )
116107
117108 endpoint , err := nginxC .Endpoint (ctx , "http" )
118- if err != nil {
119- t .Errorf ("Expected server endpoint. Got '%v'." , err )
120- }
109+ require .NoErrorf (t , err , "Expected server endpoint" )
121110
122111 resp , err := http .Get (endpoint )
123112 require .NoError (t , err )
124113 defer resp .Body .Close ()
125114
126- if resp .StatusCode != http .StatusOK {
127- t .Errorf ("Expected status code %d. Got %d." , http .StatusOK , resp .StatusCode )
128- }
115+ require .Equalf (t , http .StatusOK , resp .StatusCode , "Expected status code %d. Got %d." , http .StatusOK , resp .StatusCode )
129116}
130117
131118func TestContainerWithNetworkModeAndNetworkTogether (t * testing.T ) {
@@ -192,25 +179,17 @@ func TestContainerWithHostNetwork(t *testing.T) {
192179 require .NoError (t , err )
193180
194181 portEndpoint , err := nginxC .PortEndpoint (ctx , nginxHighPort , "http" )
195- if err != nil {
196- t .Errorf ("Expected port endpoint %s. Got '%d'." , portEndpoint , err )
197- }
182+ require .NoErrorf (t , err , "Expected port endpoint %s" , portEndpoint )
198183 t .Log (portEndpoint )
199184
200185 _ , err = http .Get (portEndpoint )
201- if err != nil {
202- t .Errorf ("Expected OK response. Got '%v'." , err )
203- }
186+ require .NoErrorf (t , err , "Expected OK response" )
204187
205188 host , err := nginxC .Host (ctx )
206- if err != nil {
207- t .Errorf ("Expected host %s. Got '%d'." , host , err )
208- }
189+ require .NoErrorf (t , err , "Expected host %s" , host )
209190
210191 _ , err = http .Get ("http://" + host + ":8080" )
211- if err != nil {
212- t .Errorf ("Expected OK response. Got '%v'." , err )
213- }
192+ assert .NoErrorf (t , err , "Expected OK response" )
214193}
215194
216195func TestContainerReturnItsContainerID (t * testing.T ) {
@@ -227,9 +206,7 @@ func TestContainerReturnItsContainerID(t *testing.T) {
227206 CleanupContainer (t , nginxA )
228207 require .NoError (t , err )
229208
230- if nginxA .GetContainerID () == "" {
231- t .Errorf ("expected a containerID but we got an empty string." )
232- }
209+ assert .NotEmptyf (t , nginxA .GetContainerID (), "expected a containerID but we got an empty string." )
233210}
234211
235212// testLogConsumer is a simple implementation of LogConsumer that logs to the test output.
@@ -419,9 +396,7 @@ func TestTwoContainersExposingTheSamePort(t *testing.T) {
419396 require .NoError (t , err )
420397 defer resp .Body .Close ()
421398
422- if resp .StatusCode != http .StatusOK {
423- t .Errorf ("Expected status code %d. Got %d." , http .StatusOK , resp .StatusCode )
424- }
399+ require .Equalf (t , http .StatusOK , resp .StatusCode , "Expected status code %d. Got %d." , http .StatusOK , resp .StatusCode )
425400
426401 endpointB , err := nginxB .PortEndpoint (ctx , nginxDefaultPort , "http" )
427402 require .NoError (t , err )
@@ -430,9 +405,7 @@ func TestTwoContainersExposingTheSamePort(t *testing.T) {
430405 require .NoError (t , err )
431406 defer resp .Body .Close ()
432407
433- if resp .StatusCode != http .StatusOK {
434- t .Errorf ("Expected status code %d. Got %d." , http .StatusOK , resp .StatusCode )
435- }
408+ require .Equalf (t , http .StatusOK , resp .StatusCode , "Expected status code %d. Got %d." , http .StatusOK , resp .StatusCode )
436409}
437410
438411func TestContainerCreation (t * testing.T ) {
@@ -459,24 +432,15 @@ func TestContainerCreation(t *testing.T) {
459432 require .NoError (t , err )
460433 defer resp .Body .Close ()
461434
462- if resp .StatusCode != http .StatusOK {
463- t .Errorf ("Expected status code %d. Got %d." , http .StatusOK , resp .StatusCode )
464- }
435+ require .Equalf (t , http .StatusOK , resp .StatusCode , "Expected status code %d. Got %d." , http .StatusOK , resp .StatusCode )
465436 networkIP , err := nginxC .ContainerIP (ctx )
466437 require .NoError (t , err )
467- if len (networkIP ) == 0 {
468- t .Errorf ("Expected an IP address, got %v" , networkIP )
469- }
438+ require .NotEmptyf (t , networkIP , "Expected an IP address, got %v" , networkIP )
470439 networkAliases , err := nginxC .NetworkAliases (ctx )
471440 require .NoError (t , err )
472- if len (networkAliases ) != 1 {
473- fmt .Printf ("%v" , networkAliases )
474- t .Errorf ("Expected number of connected networks %d. Got %d." , 0 , len (networkAliases ))
475- }
476-
477- if len (networkAliases ["bridge" ]) != 0 {
478- t .Errorf ("Expected number of aliases for 'bridge' network %d. Got %d." , 0 , len (networkAliases ["bridge" ]))
479- }
441+ require .Lenf (t , networkAliases , 1 , "Expected number of connected networks %d. Got %d." , 0 , len (networkAliases ))
442+ require .Contains (t , networkAliases , "bridge" )
443+ assert .Emptyf (t , networkAliases ["bridge" ], "Expected number of aliases for 'bridge' network %d. Got %d." , 0 , len (networkAliases ["bridge" ]))
480444}
481445
482446func TestContainerCreationWithName (t * testing.T ) {
@@ -505,24 +469,16 @@ func TestContainerCreationWithName(t *testing.T) {
505469 require .NoError (t , err )
506470
507471 name := inspect .Name
508- if name != expectedName {
509- t .Errorf ("Expected container name '%s'. Got '%s'." , expectedName , name )
510- }
472+ assert .Equalf (t , expectedName , name , "Expected container name '%s'. Got '%s'." , expectedName , name )
511473 networks , err := nginxC .Networks (ctx )
512474 require .NoError (t , err )
513- if len (networks ) != 1 {
514- t .Errorf ("Expected networks 1. Got '%d'." , len (networks ))
515- }
475+ require .Lenf (t , networks , 1 , "Expected networks 1. Got '%d'." , len (networks ))
516476 network := networks [0 ]
517477 switch providerType {
518478 case ProviderDocker :
519- if network != Bridge {
520- t .Errorf ("Expected network name '%s'. Got '%s'." , Bridge , network )
521- }
479+ assert .Equalf (t , Bridge , network , "Expected network name '%s'. Got '%s'." , Bridge , network )
522480 case ProviderPodman :
523- if network != Podman {
524- t .Errorf ("Expected network name '%s'. Got '%s'." , Podman , network )
525- }
481+ assert .Equalf (t , Podman , network , "Expected network name '%s'. Got '%s'." , Podman , network )
526482 }
527483
528484 endpoint , err := nginxC .PortEndpoint (ctx , nginxDefaultPort , "http" )
@@ -532,9 +488,7 @@ func TestContainerCreationWithName(t *testing.T) {
532488 require .NoError (t , err )
533489 defer resp .Body .Close ()
534490
535- if resp .StatusCode != http .StatusOK {
536- t .Errorf ("Expected status code %d. Got %d." , http .StatusOK , resp .StatusCode )
537- }
491+ require .Equalf (t , http .StatusOK , resp .StatusCode , "Expected status code %d. Got %d." , http .StatusOK , resp .StatusCode )
538492}
539493
540494func TestContainerCreationAndWaitForListeningPortLongEnough (t * testing.T ) {
@@ -561,9 +515,7 @@ func TestContainerCreationAndWaitForListeningPortLongEnough(t *testing.T) {
561515 require .NoError (t , err )
562516 defer resp .Body .Close ()
563517
564- if resp .StatusCode != http .StatusOK {
565- t .Errorf ("Expected status code %d. Got %d." , http .StatusOK , resp .StatusCode )
566- }
518+ require .Equalf (t , http .StatusOK , resp .StatusCode , "Expected status code %d. Got %d." , http .StatusOK , resp .StatusCode )
567519}
568520
569521func TestContainerCreationTimesOut (t * testing.T ) {
@@ -582,9 +534,7 @@ func TestContainerCreationTimesOut(t *testing.T) {
582534 })
583535 CleanupContainer (t , nginxC )
584536
585- if err == nil {
586- t .Error ("Expected timeout" )
587- }
537+ assert .Errorf (t , err , "Expected timeout" )
588538}
589539
590540func TestContainerRespondsWithHttp200ForIndex (t * testing.T ) {
@@ -610,9 +560,7 @@ func TestContainerRespondsWithHttp200ForIndex(t *testing.T) {
610560 require .NoError (t , err )
611561 defer resp .Body .Close ()
612562
613- if resp .StatusCode != http .StatusOK {
614- t .Errorf ("Expected status code %d. Got %d." , http .StatusOK , resp .StatusCode )
615- }
563+ require .Equalf (t , http .StatusOK , resp .StatusCode , "Expected status code %d. Got %d." , http .StatusOK , resp .StatusCode )
616564}
617565
618566func TestContainerCreationTimesOutWithHttp (t * testing.T ) {
@@ -650,9 +598,7 @@ func TestContainerCreationWaitsForLogContextTimeout(t *testing.T) {
650598 Started : true ,
651599 })
652600 CleanupContainer (t , c )
653- if err == nil {
654- t .Error ("Expected timeout" )
655- }
601+ assert .Errorf (t , err , "Expected timeout" )
656602}
657603
658604func TestContainerCreationWaitsForLog (t * testing.T ) {
@@ -755,10 +701,8 @@ func Test_BuildContainerFromDockerfileWithBuildLog(t *testing.T) {
755701 require .NoError (t , err )
756702
757703 temp := strings .Split (string (out ), "\n " )
758-
759- if ! regexp .MustCompile (`^Step\s*1/\d+\s*:\s*FROM alpine$` ).MatchString (temp [0 ]) {
760- t .Errorf ("Expected stdout first line to be %s. Got '%s'." , "Step 1/* : FROM alpine" , temp [0 ])
761- }
704+ require .NotEmpty (t , temp )
705+ assert .Regexpf (t , `^Step\s*1/\d+\s*:\s*FROM alpine$` , temp [0 ], "Expected stdout first line to be %s. Got '%s'." , "Step 1/* : FROM alpine" , temp [0 ])
762706}
763707
764708func TestContainerCreationWaitsForLogAndPortContextTimeout (t * testing.T ) {
0 commit comments