@@ -159,16 +159,15 @@ func TestDockerImageAuth(t *testing.T) {
159159
160160func TestBuildContainerFromDockerfile (t * testing.T ) {
161161 ctx := context .Background ()
162- req := ContainerRequest {
163- FromDockerfile : FromDockerfile {
164- Context : "./testdata" ,
165- },
166- AlwaysPullImage : true , // make sure the authentication takes place
167- ExposedPorts : []string {"6379/tcp" },
168- WaitingFor : wait .ForLog ("Ready to accept connections" ),
169- }
170162
171- redisC , err := prepareRedisImage (ctx , req )
163+ redisC , err := Run (ctx , "" ,
164+ WithDockerfile (FromDockerfile {
165+ Context : "./testdata" ,
166+ }),
167+ WithAlwaysPull (),
168+ WithExposedPorts ("6379/tcp" ),
169+ WithWaitStrategy (wait .ForLog ("Ready to accept connections" )),
170+ )
172171 CleanupContainer (t , redisC )
173172 require .NoError (t , err )
174173}
@@ -201,21 +200,19 @@ func TestBuildContainerFromDockerfileWithDockerAuthConfig(t *testing.T) {
201200
202201 ctx := context .Background ()
203202
204- req := ContainerRequest {
205- FromDockerfile : FromDockerfile {
203+ redisC , err := Run ( ctx , "" ,
204+ WithDockerfile ( FromDockerfile {
206205 Context : "./testdata" ,
207206 Dockerfile : "auth.Dockerfile" ,
208207 BuildArgs : map [string ]* string {
209208 "REGISTRY_HOST" : & registryHost ,
210209 },
211210 Repo : "localhost" ,
212- },
213- AlwaysPullImage : true , // make sure the authentication takes place
214- ExposedPorts : []string {"6379/tcp" },
215- WaitingFor : wait .ForLog ("Ready to accept connections" ),
216- }
217-
218- redisC , err := prepareRedisImage (ctx , req )
211+ }),
212+ WithAlwaysPull (),
213+ WithExposedPorts ("6379/tcp" ),
214+ WithWaitStrategy (wait .ForLog ("Ready to accept connections" )),
215+ )
219216 CleanupContainer (t , redisC )
220217 require .NoError (t , err )
221218}
@@ -228,20 +225,18 @@ func TestBuildContainerFromDockerfileShouldFailWithWrongDockerAuthConfig(t *test
228225
229226 ctx := context .Background ()
230227
231- req := ContainerRequest {
232- FromDockerfile : FromDockerfile {
228+ redisC , err := Run ( ctx , "" ,
229+ WithDockerfile ( FromDockerfile {
233230 Context : "./testdata" ,
234231 Dockerfile : "auth.Dockerfile" ,
235232 BuildArgs : map [string ]* string {
236233 "REGISTRY_HOST" : & registryHost ,
237234 },
238- },
239- AlwaysPullImage : true , // make sure the authentication takes place
240- ExposedPorts : []string {"6379/tcp" },
241- WaitingFor : wait .ForLog ("Ready to accept connections" ),
242- }
243-
244- redisC , err := prepareRedisImage (ctx , req )
235+ }),
236+ WithAlwaysPull (),
237+ WithExposedPorts ("6379/tcp" ),
238+ WithWaitStrategy (wait .ForLog ("Ready to accept connections" )),
239+ )
245240 CleanupContainer (t , redisC )
246241 require .Error (t , err )
247242}
@@ -253,17 +248,8 @@ func TestCreateContainerFromPrivateRegistry(t *testing.T) {
253248 setAuthConfig (t , registryHost , "testuser" , "testpassword" )
254249
255250 ctx := context .Background ()
256- req := ContainerRequest {
257- Image : registryHost + "/redis:5.0-alpine" ,
258- AlwaysPullImage : true , // make sure the authentication takes place
259- ExposedPorts : []string {"6379/tcp" },
260- WaitingFor : wait .ForLog ("Ready to accept connections" ),
261- }
262251
263- redisContainer , err := GenericContainer (ctx , GenericContainerRequest {
264- ContainerRequest : req ,
265- Started : true ,
266- })
252+ redisContainer , err := Run (ctx , registryHost + "/redis:5.0-alpine" , WithAlwaysPull (), WithExposedPorts ("6379/tcp" ), WithWaitStrategy (wait .ForLog ("Ready to accept connections" )))
267253 CleanupContainer (t , redisContainer )
268254 require .NoError (t , err )
269255}
@@ -274,36 +260,28 @@ func prepareLocalRegistryWithAuth(t *testing.T) string {
274260 wd , err := os .Getwd ()
275261 require .NoError (t , err )
276262 // copyDirectoryToContainer {
277- req := ContainerRequest {
278- Image : "registry:2" ,
279- ExposedPorts : []string {"5000/tcp" },
280- Env : map [string ]string {
263+ registryC , err := Run (ctx , "registry:2" ,
264+ WithAlwaysPull (),
265+ WithEnv (map [string ]string {
281266 "REGISTRY_AUTH" : "htpasswd" ,
282267 "REGISTRY_AUTH_HTPASSWD_REALM" : "Registry" ,
283268 "REGISTRY_AUTH_HTPASSWD_PATH" : "/auth/htpasswd" ,
284269 "REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY" : "/data" ,
285- },
286- Files : [] ContainerFile {
287- {
288- HostFilePath : wd + "/ testdata/ auth" ,
270+ }) ,
271+ WithFiles (
272+ ContainerFile {
273+ HostFilePath : filepath . Join ( wd , " testdata" , " auth") ,
289274 ContainerFilePath : "/auth" ,
290275 },
291- {
292- HostFilePath : wd + "/ testdata/ data" ,
276+ ContainerFile {
277+ HostFilePath : filepath . Join ( wd , " testdata" , " data") ,
293278 ContainerFilePath : "/data" ,
294279 },
295- },
296- WaitingFor : wait .ForHTTP ("/" ).WithPort ("5000/tcp" ),
297- }
280+ ),
281+ WithExposedPorts ("5000/tcp" ),
282+ WithWaitStrategy (wait .ForHTTP ("/" ).WithPort ("5000/tcp" )),
283+ )
298284 // }
299-
300- genContainerReq := GenericContainerRequest {
301- ProviderType : providerType ,
302- ContainerRequest : req ,
303- Started : true ,
304- }
305-
306- registryC , err := GenericContainer (ctx , genContainerReq )
307285 CleanupContainer (t , registryC )
308286 require .NoError (t , err )
309287
@@ -321,16 +299,6 @@ func prepareLocalRegistryWithAuth(t *testing.T) string {
321299 return addr
322300}
323301
324- func prepareRedisImage (ctx context.Context , req ContainerRequest ) (Container , error ) {
325- genContainerReq := GenericContainerRequest {
326- ProviderType : providerType ,
327- ContainerRequest : req ,
328- Started : true ,
329- }
330-
331- return GenericContainer (ctx , genContainerReq )
332- }
333-
334302// setAuthConfig sets the DOCKER_AUTH_CONFIG environment variable with
335303// authentication for with the given host, username and password.
336304// It returns the base64 encoded credentials.
0 commit comments