11package com .github .dockerjava .client .command ;
22
33import static org .hamcrest .MatcherAssert .assertThat ;
4- import static org .hamcrest .Matchers .contains ;
5- import static org .hamcrest .Matchers .isEmptyString ;
6- import static org .hamcrest .Matchers .not ;
4+ import static org .hamcrest .Matchers .*;
5+
76
87import java .lang .reflect .Method ;
8+ import java .util .Arrays ;
99
1010import org .testng .ITestResult ;
1111import org .testng .annotations .AfterMethod ;
@@ -43,11 +43,13 @@ public void afterMethod(ITestResult result) {
4343 }
4444
4545 @ Test
46- public void createContainer () throws DockerException {
46+ public void createContainerWithVolume () throws DockerException {
4747
4848 ContainerCreateResponse container = dockerClient
4949 .createContainerCmd ("busybox" ).withVolumes (new Volume ("/var/log" )).withCmd ("true" ).exec ();
5050
51+ tmpContainers .add (container .getId ());
52+
5153 LOG .info ("Created container {}" , container .toString ());
5254
5355 assertThat (container .getId (), not (isEmptyString ()));
@@ -58,9 +60,50 @@ public void createContainer() throws DockerException {
5860
5961 assertThat (containerInspectResponse .getConfig ().getVolumes ().keySet (), contains ("/var/log" ));
6062
63+
64+ }
65+
66+ @ Test
67+ public void createContainerWithEnv () throws DockerException {
68+
69+ ContainerCreateResponse container = dockerClient
70+ .createContainerCmd ("busybox" ).withEnv ("VARIABLE=success" ).withCmd ("env" ).exec ();
71+
6172 tmpContainers .add (container .getId ());
73+
74+ LOG .info ("Created container {}" , container .toString ());
75+
76+ assertThat (container .getId (), not (isEmptyString ()));
77+
78+ ContainerInspectResponse containerInspectResponse = dockerClient .inspectContainerCmd (container .getId ()).exec ();
79+
80+ assertThat (Arrays .asList (containerInspectResponse .getConfig ().getEnv ()), contains ("VARIABLE=success" ,"HOME=/" ,"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ));
81+
82+ dockerClient .startContainerCmd (container .getId ()).exec ();
83+
84+ assertThat (logResponseStream (dockerClient .logContainerCmd (container .getId ()).withStdOut ().exec ()), containsString ("VARIABLE=success" ));
6285 }
6386
87+ @ Test
88+ public void createContainerWithHostname () throws DockerException {
89+
90+ ContainerCreateResponse container = dockerClient
91+ .createContainerCmd ("busybox" ).withHostName ("docker-java" ).withCmd ("env" ).exec ();
92+
93+ tmpContainers .add (container .getId ());
94+
95+ LOG .info ("Created container {}" , container .toString ());
96+
97+ assertThat (container .getId (), not (isEmptyString ()));
98+
99+ ContainerInspectResponse containerInspectResponse = dockerClient .inspectContainerCmd (container .getId ()).exec ();
100+
101+ assertThat (containerInspectResponse .getConfig ().getHostName (), equalTo ("docker-java" ));
102+
103+ dockerClient .startContainerCmd (container .getId ()).exec ();
104+
105+ assertThat (logResponseStream (dockerClient .logContainerCmd (container .getId ()).withStdOut ().exec ()), containsString ("HOSTNAME=docker-java" ));
106+ }
64107
65108
66109}
0 commit comments