Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.gesellix.docker.remote.api.client;

import com.squareup.moshi.Moshi;

import de.gesellix.docker.registry.LocalDocker;
import de.gesellix.docker.remote.api.ContainerCreateRequest;
import de.gesellix.docker.remote.api.ContainerCreateResponse;
import de.gesellix.docker.remote.api.ContainerInspectResponse;
Expand Down Expand Up @@ -931,6 +933,16 @@ null, null, singletonList("/cat"),
null,
null
);
if (LocalDocker.isNativeWindows()) {
containerCreateRequest.setTty(false);
containerCreateRequest.setEntrypoint(singletonList("cmd"));
containerCreateRequest.setCmd(Arrays.asList("/V:ON", "/C", "set /p line= & echo #!line!#"));
} else {
containerCreateRequest.setTty(false);
containerCreateRequest.setEntrypoint(singletonList("/bin/sh"));
containerCreateRequest.setCmd(Arrays.asList("-c", "read line && echo \"#$line#\""));
}

containerApi.containerCreate(containerCreateRequest, "container-attach-interactive-test");
containerApi.containerStart("container-attach-interactive-test", null);

Expand Down Expand Up @@ -981,10 +993,18 @@ public void run() {
} catch (InterruptedException e) {
e.printStackTrace();
}
assertSame(Frame.StreamType.RAW, callback.frames.stream().findAny().get().getStreamType());
assertEquals(
"hello echo\nhello echo".replaceAll("[\\n\\r]", ""),
callback.frames.stream().map(Frame::getPayloadAsString).collect(Collectors.joining()).replaceAll("[\\n\\r]", ""));

if (containerCreateRequest.getTty() != null && containerCreateRequest.getTty()) {
assertSame(Frame.StreamType.RAW, callback.frames.stream().findAny().get().getStreamType());
assertEquals(
"hello echo\nhello echo".replaceAll("[\\n\\r]", ""),
callback.frames.stream().map(Frame::getPayloadAsString).collect(Collectors.joining()).replaceAll("[\\n\\r]", ""));
} else {
assertSame(Frame.StreamType.STDOUT, callback.frames.stream().findAny().get().getStreamType());
assertEquals(
"#hello echo#",
callback.frames.stream().map(Frame::getPayloadAsString).collect(Collectors.joining()).replaceAll("[\\n\\r]", ""));
}

removeContainer(engineApiClient, "container-attach-interactive-test");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.gesellix.docker.remote.api.client;

import de.gesellix.docker.registry.LocalDocker;
import de.gesellix.docker.remote.api.ContainerCreateRequest;
import de.gesellix.docker.remote.api.EngineApiClient;
import de.gesellix.docker.remote.api.ExecConfig;
Expand Down Expand Up @@ -29,10 +30,10 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.time.Duration;
import java.util.Arrays;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -130,12 +131,20 @@ public void containerExecInteractive() {
containerApi.containerCreate(containerCreateRequest, "container-exec-interactive-test");
containerApi.containerStart("container-exec-interactive-test", null);

IdResponse exec = execApi.containerExec(
"container-exec-interactive-test",
new ExecConfig(true, true, true, null, null, true,
null,
singletonList("/cat"),
null, null, null));
ExecConfig execConfig = new ExecConfig(true, true, true, null, null, false,
null,
singletonList("/cat"),
null, null, null);

if (LocalDocker.isNativeWindows()) {
execConfig.setTty(false);
execConfig.setCmd(Arrays.asList("cmd", "/V:ON", "/C", "set /p line= & echo #!line!#"));
} else {
execConfig.setTty(false);
execConfig.setCmd(Arrays.asList("/bin/sh", "-c", "read line && echo \"#$line#\""));
}

IdResponse exec = execApi.containerExec("container-exec-interactive-test", execConfig);
assertNotNull(exec.getId());

Duration timeout = Duration.of(5, SECONDS);
Expand Down Expand Up @@ -187,13 +196,20 @@ public void run() {
e.printStackTrace();
}

ExecInspectResponse execInspect = execApi.execInspect(exec.getId());
assertTrue(execInspect.getRunning());

assertSame(Frame.StreamType.RAW, callback.frames.stream().findAny().get().getStreamType());
assertEquals(
"hello echo\nhello echo".replaceAll("[\\n\\r]", ""),
callback.frames.stream().map(Frame::getPayloadAsString).collect(Collectors.joining()).replaceAll("[\\n\\r]", ""));
// ExecInspectResponse execInspect = execApi.execInspect(exec.getId());
// assertTrue(execInspect.getRunning());

if (execConfig.getTty() != null && execConfig.getTty()) {
assertSame(Frame.StreamType.RAW, callback.frames.stream().findAny().get().getStreamType());
assertEquals(
"hello echo\nhello echo".replaceAll("[\\n\\r]", ""),
callback.frames.stream().map(Frame::getPayloadAsString).collect(Collectors.joining()).replaceAll("[\\n\\r]", ""));
} else {
assertSame(Frame.StreamType.RAW, callback.frames.stream().findAny().get().getStreamType());
assertEquals(
"#hello echo#",
callback.frames.stream().map(Frame::getPayloadAsString).collect(Collectors.joining()).replaceAll("[\\n\\r]", ""));
}

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

Expand Down
Loading