@@ -17,6 +17,7 @@ import (
1717 "time"
1818
1919 "github.com/docker/docker/api/types/container"
20+ "github.com/docker/docker/api/types/strslice"
2021 "github.com/docker/go-units"
2122 "github.com/go-redis/redis/v8"
2223 "github.com/stretchr/testify/assert"
@@ -1959,6 +1960,39 @@ func TestContainerWithReaperNetwork(t *testing.T) {
19591960 assert .NotNil (t , cnt .NetworkSettings .Networks [networks [1 ]])
19601961}
19611962
1963+ func TestContainerCapAdd (t * testing.T ) {
1964+ if providerType == ProviderPodman {
1965+ t .Skip ("Rootless Podman does not support setting cap-add/cap-drop" )
1966+ }
1967+
1968+ ctx := context .Background ()
1969+
1970+ expected := "IPC_LOCK"
1971+
1972+ nginx , err := GenericContainer (ctx , GenericContainerRequest {
1973+ ProviderType : providerType ,
1974+ ContainerRequest : ContainerRequest {
1975+ Image : nginxAlpineImage ,
1976+ ExposedPorts : []string {nginxDefaultPort },
1977+ WaitingFor : wait .ForListeningPort (nginxDefaultPort ),
1978+ CapAdd : []string {expected },
1979+ },
1980+ Started : true ,
1981+ })
1982+ require .NoError (t , err )
1983+ terminateContainerOnEnd (t , ctx , nginx )
1984+
1985+ dockerClient , err := client .NewClientWithOpts (client .FromEnv , client .WithAPIVersionNegotiation ())
1986+ require .NoError (t , err )
1987+ defer dockerClient .Close ()
1988+
1989+ containerID := nginx .GetContainerID ()
1990+ resp , err := dockerClient .ContainerInspect (ctx , containerID )
1991+ require .NoError (t , err )
1992+
1993+ assert .Equal (t , strslice.StrSlice {expected }, resp .HostConfig .CapAdd )
1994+ }
1995+
19621996func TestContainerRunningCheckingStatusCode (t * testing.T ) {
19631997 ctx := context .Background ()
19641998 req := ContainerRequest {
@@ -2068,6 +2102,33 @@ func TestProviderHasConfig(t *testing.T) {
20682102 assert .NotNil (t , provider .Config (), "expecting DockerProvider to provide the configuration" )
20692103}
20702104
2105+ func TestNetworkModeWithContainerReference (t * testing.T ) {
2106+ ctx := context .Background ()
2107+ nginxA , err := GenericContainer (ctx , GenericContainerRequest {
2108+ ProviderType : providerType ,
2109+ ContainerRequest : ContainerRequest {
2110+ Image : nginxAlpineImage ,
2111+ },
2112+ Started : true ,
2113+ })
2114+
2115+ require .NoError (t , err )
2116+ terminateContainerOnEnd (t , ctx , nginxA )
2117+
2118+ networkMode := fmt .Sprintf ("container:%v" , nginxA .GetContainerID ())
2119+ nginxB , err := GenericContainer (ctx , GenericContainerRequest {
2120+ ProviderType : providerType ,
2121+ ContainerRequest : ContainerRequest {
2122+ Image : nginxAlpineImage ,
2123+ NetworkMode : container .NetworkMode (networkMode ),
2124+ },
2125+ Started : true ,
2126+ })
2127+
2128+ require .NoError (t , err )
2129+ terminateContainerOnEnd (t , ctx , nginxB )
2130+ }
2131+
20712132// creates a temporary dir in which the files will be extracted. Then it will compare the bytes of each file in the source with the bytes from the copied-from-container file
20722133func assertExtractedFiles (t * testing.T , ctx context.Context , container Container , hostFilePath string , containerFilePath string ) {
20732134 // create all copied files into a temporary dir
0 commit comments