|
1 | 1 | package de.gesellix.docker.remote.api.client; |
2 | 2 |
|
| 3 | +import de.gesellix.docker.registry.LocalDocker; |
3 | 4 | import de.gesellix.docker.remote.api.ContainerCreateRequest; |
4 | 5 | import de.gesellix.docker.remote.api.EngineApiClient; |
5 | 6 | import de.gesellix.docker.remote.api.ExecConfig; |
|
29 | 30 | import static org.junit.jupiter.api.Assertions.assertFalse; |
30 | 31 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
31 | 32 | import static org.junit.jupiter.api.Assertions.assertSame; |
32 | | -import static org.junit.jupiter.api.Assertions.assertTrue; |
33 | 33 |
|
34 | 34 | import java.io.IOException; |
35 | 35 | import java.time.Duration; |
| 36 | +import java.util.Arrays; |
36 | 37 | import java.util.Timer; |
37 | 38 | import java.util.TimerTask; |
38 | 39 | import java.util.concurrent.CountDownLatch; |
@@ -130,12 +131,20 @@ public void containerExecInteractive() { |
130 | 131 | containerApi.containerCreate(containerCreateRequest, "container-exec-interactive-test"); |
131 | 132 | containerApi.containerStart("container-exec-interactive-test", null); |
132 | 133 |
|
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); |
139 | 148 | assertNotNull(exec.getId()); |
140 | 149 |
|
141 | 150 | Duration timeout = Duration.of(5, SECONDS); |
@@ -187,13 +196,20 @@ public void run() { |
187 | 196 | e.printStackTrace(); |
188 | 197 | } |
189 | 198 |
|
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 | + } |
197 | 213 |
|
198 | 214 | removeContainer(engineApiClient, "container-exec-interactive-test"); |
199 | 215 |
|
|
0 commit comments