55 "database/sql"
66 "errors"
77 "fmt"
8+ // Import mysql into the scope of this package (required)
9+ _ "github.com/go-sql-driver/mysql"
810 "io"
911 "io/ioutil"
1012 "math/rand"
@@ -29,9 +31,6 @@ import (
2931
3032 "github.com/docker/docker/api/types/volume"
3133
32- // Import mysql into the scope of this package (required)
33- _ "github.com/go-sql-driver/mysql"
34-
3534 "github.com/docker/docker/api/types"
3635 "github.com/docker/docker/api/types/filters"
3736 "github.com/docker/docker/client"
@@ -2496,3 +2495,40 @@ func randomString() string {
24962495 }
24972496 return b .String ()
24982497}
2498+
2499+ func TestDockerProviderFindContainerByName (t * testing.T ) {
2500+ ctx := context .Background ()
2501+ provider , err := NewDockerProvider (WithLogger (TestLogger (t )))
2502+ require .NoError (t , err )
2503+
2504+ c1 , err := GenericContainer (ctx , GenericContainerRequest {
2505+ ProviderType : providerType ,
2506+ ContainerRequest : ContainerRequest {
2507+ Name : "test" ,
2508+ Image : "nginx:1.17.6" ,
2509+ WaitingFor : wait .ForExposedPort (),
2510+ },
2511+ Started : true ,
2512+ })
2513+ require .NoError (t , err )
2514+ c1Name , err := c1 .Name (ctx )
2515+ require .NoError (t , err )
2516+ terminateContainerOnEnd (t , ctx , c1 )
2517+
2518+ c2 , err := GenericContainer (ctx , GenericContainerRequest {
2519+ ProviderType : providerType ,
2520+ ContainerRequest : ContainerRequest {
2521+ Name : "test2" ,
2522+ Image : "nginx:1.17.6" ,
2523+ WaitingFor : wait .ForExposedPort (),
2524+ },
2525+ Started : true ,
2526+ })
2527+ require .NoError (t , err )
2528+ terminateContainerOnEnd (t , ctx , c2 )
2529+
2530+ c , err := provider .findContainerByName (ctx , "test" )
2531+ assert .NoError (t , err )
2532+ require .NotNil (t , c )
2533+ assert .Contains (t , c .Names , c1Name )
2534+ }
0 commit comments