@@ -12,7 +12,6 @@ import (
1212
1313 "github.com/docker/docker/api/types/build"
1414 "github.com/docker/docker/api/types/container"
15- "github.com/stretchr/testify/assert"
1615 "github.com/stretchr/testify/require"
1716
1817 "github.com/testcontainers/testcontainers-go"
@@ -325,7 +324,7 @@ func TestCustomLabelsImage(t *testing.T) {
325324
326325 ctrJSON , err := ctr .Inspect (ctx )
327326 require .NoError (t , err )
328- assert .Equal (t , myLabelValue , ctrJSON .Config .Labels [myLabelName ])
327+ require .Equal (t , myLabelValue , ctrJSON .Config .Labels [myLabelName ])
329328}
330329
331330func TestCustomLabelsBuildOptionsModifier (t * testing.T ) {
@@ -363,17 +362,12 @@ func TestCustomLabelsBuildOptionsModifier(t *testing.T) {
363362func Test_GetLogsFromFailedContainer (t * testing.T ) {
364363 ctx := context .Background ()
365364 // directDockerHubReference {
366- req := testcontainers.ContainerRequest {
367- Image : "alpine" ,
368- Cmd : [] string { "echo" , "-n" , "I was not expecting this" } ,
369- WaitingFor : wait .ForLog ("I was expecting this" ).WithStartupTimeout (5 * time .Second ),
370- }
365+ c , err := testcontainers .Run (
366+ ctx , "alpine" ,
367+ testcontainers . WithCmd ( "echo" , "-n" , "I was not expecting this" ) ,
368+ testcontainers . WithWaitStrategy ( wait .ForLog ("I was expecting this" ).WithStartupTimeout (5 * time .Second ) ),
369+ )
371370 // }
372-
373- c , err := testcontainers .GenericContainer (ctx , testcontainers.GenericContainerRequest {
374- ContainerRequest : req ,
375- Started : true ,
376- })
377371 testcontainers .CleanupContainer (t , c )
378372 require .ErrorContains (t , err , "container exited with code 0" )
379373
@@ -468,27 +462,15 @@ func TestImageSubstitutors(t *testing.T) {
468462 for _ , test := range tests {
469463 t .Run (test .name , func (t * testing.T ) {
470464 ctx := context .Background ()
471- req := testcontainers.ContainerRequest {
472- Image : test .image ,
473- ImageSubstitutors : test .substitutors ,
474- }
475-
476- ctr , err := testcontainers .GenericContainer (ctx , testcontainers.GenericContainerRequest {
477- ContainerRequest : req ,
478- Started : true ,
479- })
465+ ctr , err := testcontainers .Run (ctx , test .image , testcontainers .WithImageSubstitutors (test .substitutors ... ))
480466 testcontainers .CleanupContainer (t , ctr )
481467 if test .expectedError != nil {
482468 require .ErrorIs (t , err , test .expectedError )
483469 return
484470 }
485471
486472 require .NoError (t , err )
487-
488- // enforce the concrete type, as GenericContainer returns an interface,
489- // which will be changed in future implementations of the library
490- dockerContainer := ctr .(* testcontainers.DockerContainer )
491- assert .Equal (t , test .expectedImage , dockerContainer .Image )
473+ require .Equal (t , test .expectedImage , ctr .Image )
492474 })
493475 }
494476}
@@ -502,15 +484,11 @@ func TestShouldStartContainersInParallel(t *testing.T) {
502484 t .Run (fmt .Sprintf ("iteration_%d" , i ), func (t * testing.T ) {
503485 t .Parallel ()
504486
505- req := testcontainers.ContainerRequest {
506- Image : nginxAlpineImage ,
507- ExposedPorts : []string {nginxDefaultPort },
508- WaitingFor : wait .ForHTTP ("/" ).WithStartupTimeout (10 * time .Second ),
509- }
510- ctr , err := testcontainers .GenericContainer (ctx , testcontainers.GenericContainerRequest {
511- ContainerRequest : req ,
512- Started : true ,
513- })
487+ ctr , err := testcontainers .Run (
488+ ctx , nginxAlpineImage ,
489+ testcontainers .WithExposedPorts (nginxDefaultPort ),
490+ testcontainers .WithWaitStrategy (wait .ForHTTP ("/" ).WithStartupTimeout (10 * time .Second )),
491+ )
514492 testcontainers .CleanupContainer (t , ctr )
515493 require .NoError (t , err )
516494
@@ -528,13 +506,7 @@ func ExampleGenericContainer_withSubstitutors() {
528506 ctx := context .Background ()
529507
530508 // applyImageSubstitutors {
531- ctr , err := testcontainers .GenericContainer (ctx , testcontainers.GenericContainerRequest {
532- ContainerRequest : testcontainers.ContainerRequest {
533- Image : "alpine:latest" ,
534- ImageSubstitutors : []testcontainers.ImageSubstitutor {dockerImageSubstitutor {}},
535- },
536- Started : true ,
537- })
509+ ctr , err := testcontainers .Run (ctx , "alpine:latest" , testcontainers .WithImageSubstitutors (dockerImageSubstitutor {}))
538510 defer func () {
539511 if err := testcontainers .TerminateContainer (ctr ); err != nil {
540512 log .Printf ("failed to terminate container: %s" , err )
@@ -547,11 +519,7 @@ func ExampleGenericContainer_withSubstitutors() {
547519 return
548520 }
549521
550- // enforce the concrete type, as GenericContainer returns an interface,
551- // which will be changed in future implementations of the library
552- dockerContainer := ctr .(* testcontainers.DockerContainer )
553-
554- fmt .Println (dockerContainer .Image )
522+ fmt .Println (ctr .Image )
555523
556524 // Output: registry.hub.docker.com/library/alpine:latest
557525}
0 commit comments