Skip to content

Commit 3abc4f7

Browse files
authored
Beware of WCOW (#673)
Test with TTY=false for now, fix TTY=true later
1 parent a4cf0be commit 3abc4f7

File tree

2 files changed

+54
-18
lines changed

2 files changed

+54
-18
lines changed

api-client/src/test/java/de/gesellix/docker/remote/api/client/ContainerApiIntegrationTest.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package de.gesellix.docker.remote.api.client;
22

33
import com.squareup.moshi.Moshi;
4+
5+
import de.gesellix.docker.registry.LocalDocker;
46
import de.gesellix.docker.remote.api.ContainerCreateRequest;
57
import de.gesellix.docker.remote.api.ContainerCreateResponse;
68
import de.gesellix.docker.remote.api.ContainerInspectResponse;
@@ -931,6 +933,16 @@ null, null, singletonList("/cat"),
931933
null,
932934
null
933935
);
936+
if (LocalDocker.isNativeWindows()) {
937+
containerCreateRequest.setTty(false);
938+
containerCreateRequest.setEntrypoint(singletonList("cmd"));
939+
containerCreateRequest.setCmd(Arrays.asList("/V:ON", "/C", "set /p line= & echo #!line!#"));
940+
} else {
941+
containerCreateRequest.setTty(false);
942+
containerCreateRequest.setEntrypoint(singletonList("/bin/sh"));
943+
containerCreateRequest.setCmd(Arrays.asList("-c", "read line && echo \"#$line#\""));
944+
}
945+
934946
containerApi.containerCreate(containerCreateRequest, "container-attach-interactive-test");
935947
containerApi.containerStart("container-attach-interactive-test", null);
936948

@@ -981,10 +993,18 @@ public void run() {
981993
} catch (InterruptedException e) {
982994
e.printStackTrace();
983995
}
984-
assertSame(Frame.StreamType.RAW, callback.frames.stream().findAny().get().getStreamType());
985-
assertEquals(
986-
"hello echo\nhello echo".replaceAll("[\\n\\r]", ""),
987-
callback.frames.stream().map(Frame::getPayloadAsString).collect(Collectors.joining()).replaceAll("[\\n\\r]", ""));
996+
997+
if (containerCreateRequest.getTty() != null && containerCreateRequest.getTty()) {
998+
assertSame(Frame.StreamType.RAW, callback.frames.stream().findAny().get().getStreamType());
999+
assertEquals(
1000+
"hello echo\nhello echo".replaceAll("[\\n\\r]", ""),
1001+
callback.frames.stream().map(Frame::getPayloadAsString).collect(Collectors.joining()).replaceAll("[\\n\\r]", ""));
1002+
} else {
1003+
assertSame(Frame.StreamType.STDOUT, callback.frames.stream().findAny().get().getStreamType());
1004+
assertEquals(
1005+
"#hello echo#",
1006+
callback.frames.stream().map(Frame::getPayloadAsString).collect(Collectors.joining()).replaceAll("[\\n\\r]", ""));
1007+
}
9881008

9891009
removeContainer(engineApiClient, "container-attach-interactive-test");
9901010
}

api-client/src/test/java/de/gesellix/docker/remote/api/client/ExecApiIntegrationTest.java

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.gesellix.docker.remote.api.client;
22

3+
import de.gesellix.docker.registry.LocalDocker;
34
import de.gesellix.docker.remote.api.ContainerCreateRequest;
45
import de.gesellix.docker.remote.api.EngineApiClient;
56
import de.gesellix.docker.remote.api.ExecConfig;
@@ -29,10 +30,10 @@
2930
import static org.junit.jupiter.api.Assertions.assertFalse;
3031
import static org.junit.jupiter.api.Assertions.assertNotNull;
3132
import static org.junit.jupiter.api.Assertions.assertSame;
32-
import static org.junit.jupiter.api.Assertions.assertTrue;
3333

3434
import java.io.IOException;
3535
import java.time.Duration;
36+
import java.util.Arrays;
3637
import java.util.Timer;
3738
import java.util.TimerTask;
3839
import java.util.concurrent.CountDownLatch;
@@ -130,12 +131,20 @@ public void containerExecInteractive() {
130131
containerApi.containerCreate(containerCreateRequest, "container-exec-interactive-test");
131132
containerApi.containerStart("container-exec-interactive-test", null);
132133

133-
IdResponse exec = execApi.containerExec(
134-
"container-exec-interactive-test",
135-
new ExecConfig(true, true, true, null, null, true,
136-
null,
137-
singletonList("/cat"),
138-
null, null, null));
134+
ExecConfig execConfig = new ExecConfig(true, true, true, null, null, false,
135+
null,
136+
singletonList("/cat"),
137+
null, null, null);
138+
139+
if (LocalDocker.isNativeWindows()) {
140+
execConfig.setTty(false);
141+
execConfig.setCmd(Arrays.asList("cmd", "/V:ON", "/C", "set /p line= & echo #!line!#"));
142+
} else {
143+
execConfig.setTty(false);
144+
execConfig.setCmd(Arrays.asList("/bin/sh", "-c", "read line && echo \"#$line#\""));
145+
}
146+
147+
IdResponse exec = execApi.containerExec("container-exec-interactive-test", execConfig);
139148
assertNotNull(exec.getId());
140149

141150
Duration timeout = Duration.of(5, SECONDS);
@@ -187,13 +196,20 @@ public void run() {
187196
e.printStackTrace();
188197
}
189198

190-
ExecInspectResponse execInspect = execApi.execInspect(exec.getId());
191-
assertTrue(execInspect.getRunning());
192-
193-
assertSame(Frame.StreamType.RAW, callback.frames.stream().findAny().get().getStreamType());
194-
assertEquals(
195-
"hello echo\nhello echo".replaceAll("[\\n\\r]", ""),
196-
callback.frames.stream().map(Frame::getPayloadAsString).collect(Collectors.joining()).replaceAll("[\\n\\r]", ""));
199+
// ExecInspectResponse execInspect = execApi.execInspect(exec.getId());
200+
// assertTrue(execInspect.getRunning());
201+
202+
if (execConfig.getTty() != null && execConfig.getTty()) {
203+
assertSame(Frame.StreamType.RAW, callback.frames.stream().findAny().get().getStreamType());
204+
assertEquals(
205+
"hello echo\nhello echo".replaceAll("[\\n\\r]", ""),
206+
callback.frames.stream().map(Frame::getPayloadAsString).collect(Collectors.joining()).replaceAll("[\\n\\r]", ""));
207+
} else {
208+
assertSame(Frame.StreamType.RAW, callback.frames.stream().findAny().get().getStreamType());
209+
assertEquals(
210+
"#hello echo#",
211+
callback.frames.stream().map(Frame::getPayloadAsString).collect(Collectors.joining()).replaceAll("[\\n\\r]", ""));
212+
}
197213

198214
removeContainer(engineApiClient, "container-exec-interactive-test");
199215

0 commit comments

Comments
 (0)