@@ -229,6 +229,116 @@ public void createContainerWithEnv() throws Exception {
229229 assertThat (dockerRule .containerLog (container .getId ()), containsString (testVariable ));
230230 }
231231
232+ @ Test
233+ public void createContainerWithEnvAdditive () throws Exception {
234+
235+ final String testVariable1 = "VARIABLE1=success1" ;
236+ final String testVariable2 = "VARIABLE2=success2" ;
237+
238+ CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
239+ .withEnv (testVariable1 )
240+ .withEnv (testVariable2 )
241+ .withCmd ("env" )
242+ .exec ();
243+
244+ LOG .info ("Created container {}" , container .toString ());
245+
246+ assertThat (container .getId (), not (isEmptyString ()));
247+
248+ InspectContainerResponse inspectContainerResponse = dockerRule .getClient ().inspectContainerCmd (container .getId ()).exec ();
249+
250+ assertThat (Arrays .asList (inspectContainerResponse .getConfig ().getEnv ()), not (hasItem (testVariable1 )));
251+ assertThat (Arrays .asList (inspectContainerResponse .getConfig ().getEnv ()), hasItem (testVariable2 ));
252+
253+ dockerRule .getClient ().startContainerCmd (container .getId ()).exec ();
254+
255+ assertThat (dockerRule .containerLog (container .getId ()), not (containsString (testVariable1 )));
256+ assertThat (dockerRule .containerLog (container .getId ()), containsString (testVariable2 ));
257+ }
258+
259+ @ Test
260+ public void createContainerWithEnvAdditiveMap () throws Exception {
261+ final String [] testVariables1 = {"VARIABLE1=success1" , "VARIABLE2=success2" };
262+ final String [] testVariables2 = {"VARIABLE3=success3" , "VARIABLE4=success4" };
263+
264+ CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
265+ .withEnv (testVariables1 )
266+ .withEnv (testVariables2 )
267+ .withCmd ("env" )
268+ .exec ();
269+
270+ LOG .info ("Created container {}" , container .toString ());
271+
272+ assertThat (container .getId (), not (isEmptyString ()));
273+
274+ InspectContainerResponse inspectContainerResponse = dockerRule .getClient ().inspectContainerCmd (container .getId ()).exec ();
275+
276+ assertThat (Arrays .asList (inspectContainerResponse .getConfig ().getEnv ()), not (hasItem (testVariables1 [0 ])));
277+ assertThat (Arrays .asList (inspectContainerResponse .getConfig ().getEnv ()), not (hasItem (testVariables1 [1 ])));
278+
279+ assertThat (Arrays .asList (inspectContainerResponse .getConfig ().getEnv ()), hasItem (testVariables2 [0 ]));
280+ assertThat (Arrays .asList (inspectContainerResponse .getConfig ().getEnv ()), hasItem (testVariables2 [1 ]));
281+
282+
283+ dockerRule .getClient ().startContainerCmd (container .getId ()).exec ();
284+
285+ assertThat (dockerRule .containerLog (container .getId ()), not (containsString (testVariables1 [0 ])));
286+ assertThat (dockerRule .containerLog (container .getId ()), not (containsString (testVariables1 [1 ])));
287+
288+ assertThat (dockerRule .containerLog (container .getId ()), containsString (testVariables2 [0 ]));
289+ assertThat (dockerRule .containerLog (container .getId ()), containsString (testVariables2 [1 ]));
290+ }
291+
292+ @ Test
293+ public void createContainerWithEnvAsVararg () throws Exception {
294+
295+ final String testVariable1 = "VARIABLE1=success1" ;
296+ final String testVariable2 = "VARIABLE2=success2" ;
297+
298+ CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
299+ .withEnv (testVariable1 , testVariable2 )
300+ .withCmd ("env" )
301+ .exec ();
302+
303+ LOG .info ("Created container {}" , container .toString ());
304+
305+ assertThat (container .getId (), not (isEmptyString ()));
306+
307+ InspectContainerResponse inspectContainerResponse = dockerRule .getClient ().inspectContainerCmd (container .getId ()).exec ();
308+
309+ assertThat (Arrays .asList (inspectContainerResponse .getConfig ().getEnv ()), hasItem (testVariable1 ));
310+ assertThat (Arrays .asList (inspectContainerResponse .getConfig ().getEnv ()), hasItem (testVariable2 ));
311+
312+ dockerRule .getClient ().startContainerCmd (container .getId ()).exec ();
313+
314+ assertThat (dockerRule .containerLog (container .getId ()), containsString (testVariable1 ));
315+ assertThat (dockerRule .containerLog (container .getId ()), containsString (testVariable2 ));
316+ }
317+
318+ @ Test
319+ public void createContainerWithEnvAsMap () throws Exception {
320+ final String [] testVariables = {"VARIABLE1=success1" , "VARIABLE2=success2" };
321+
322+ CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
323+ .withEnv (testVariables )
324+ .withCmd ("env" )
325+ .exec ();
326+
327+ LOG .info ("Created container {}" , container .toString ());
328+
329+ assertThat (container .getId (), not (isEmptyString ()));
330+
331+ InspectContainerResponse inspectContainerResponse = dockerRule .getClient ().inspectContainerCmd (container .getId ()).exec ();
332+
333+ assertThat (Arrays .asList (inspectContainerResponse .getConfig ().getEnv ()), hasItem (testVariables [0 ]));
334+ assertThat (Arrays .asList (inspectContainerResponse .getConfig ().getEnv ()), hasItem (testVariables [1 ]));
335+
336+ dockerRule .getClient ().startContainerCmd (container .getId ()).exec ();
337+
338+ assertThat (dockerRule .containerLog (container .getId ()), containsString (testVariables [0 ]));
339+ assertThat (dockerRule .containerLog (container .getId ()), containsString (testVariables [1 ]));
340+ }
341+
232342 @ Test
233343 public void createContainerWithHostname () throws Exception {
234344
0 commit comments