Skip to content

Commit 4c663e1

Browse files
authored
Fix test for different API behaviour. (docker-java#642)
1 parent d78a1cf commit 4c663e1

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/main/java/com/github/dockerjava/core/RemoteApiVersion.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ public class RemoteApiVersion implements Serializable {
6262
*/
6363
public static final RemoteApiVersion VERSION_1_22 = RemoteApiVersion.create(1, 22);
6464

65+
/**
66+
* @see <a href="https://github.com/docker/docker/blob/master/docs/reference/api/docker_remote_api_v1.23.md">Docker API 1.22</a>
67+
*/
68+
public static final RemoteApiVersion VERSION_1_23 = RemoteApiVersion.create(1, 23);
69+
70+
/**
71+
* @see <a href="https://github.com/docker/docker/blob/master/docs/reference/api/docker_remote_api_v1.24.md">Docker API 1.22</a>
72+
*/
73+
public static final RemoteApiVersion VERSION_1_24 = RemoteApiVersion.create(1, 24);
74+
6575
/**
6676
* Unknown, docker doesn't reflect reality. I.e. we implemented method, but for javadoc it not clear when it was added.
6777
*/

src/test/java/com/github/dockerjava/netty/exec/ExecStartCmdExecTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.github.dockerjava.netty.exec;
22

3+
import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_22;
4+
import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_23;
5+
import static com.github.dockerjava.utils.TestUtils.getVersion;
36
import static org.hamcrest.MatcherAssert.assertThat;
47
import static org.hamcrest.Matchers.isEmptyString;
58
import static org.hamcrest.Matchers.not;
@@ -12,6 +15,7 @@
1215
import java.security.SecureRandom;
1316
import java.util.concurrent.TimeUnit;
1417

18+
import com.github.dockerjava.core.RemoteApiVersion;
1519
import org.testng.ITestResult;
1620
import org.testng.annotations.AfterMethod;
1721
import org.testng.annotations.AfterTest;
@@ -193,16 +197,22 @@ public void execStartNotAttachedStdin() throws Exception {
193197
ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(container.getId())
194198
.withAttachStdout(true)
195199
.withAttachStdin(false)
196-
.withCmd("/bin/sh").exec();
200+
.withCmd("/bin/sh")
201+
.exec();
197202

198203
boolean completed = dockerClient.execStartCmd(execCreateCmdResponse.getId())
199204
.withDetach(false)
200205
.withStdIn(stdin)
201206
.exec(new ExecStartResultCallback(stdout, System.err))
202207
.awaitCompletion(5, TimeUnit.SECONDS);
203208

204-
// with v1.22 of the remote api the server closed the connection when no stdin was attached while exec create, so completed was true
205-
assertFalse(completed, "The process was not finished.");
206209
assertEquals(stdout.toString(), "");
210+
211+
if (getVersion(dockerClient).isGreaterOrEqual(VERSION_1_23)) {
212+
assertFalse(completed, "The process was not finished.");
213+
} else {
214+
assertTrue(completed, "with v1.22 of the remote api the server closed the connection when no stdin " +
215+
"was attached while exec create, so completed was true");
216+
}
207217
}
208218
}

0 commit comments

Comments
 (0)