Skip to content
Open
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
Expand Up @@ -16,8 +16,10 @@
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -199,7 +201,11 @@ public Container.ExecResult execInContainer(
String containerId = containerInfo.getId();
String containerName = containerInfo.getName();

String[] command = execConfig.getCommand();
String[] command = Arrays
.stream(execConfig.getCommand())
.filter(Objects::nonNull)
.filter(str -> !str.trim().isEmpty())
.toArray(String[]::new);
log.debug("{}: Running \"exec\" command: {}", containerName, String.join(" ", command));
final ExecCreateCmd execCreateCmd = dockerClient
.execCreateCmd(containerId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import org.assertj.core.api.Assumptions;
import org.junit.jupiter.api.AutoClose;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.testcontainers.TestImages;
import org.testcontainers.containers.ExecConfig;
import org.testcontainers.containers.GenericContainer;
Expand Down Expand Up @@ -36,6 +39,19 @@ void shouldExecuteCommand() throws Exception {
// We expect to reach this point for modern Docker versions.
}

@ParameterizedTest
@NullSource
@ValueSource(strings = { "", " ", " " })
void shouldExecuteCommandAndSkipCommand(String commandParam) throws Exception {
Assumptions.assumeThat(TestEnvironment.dockerExecutionDriverSupportsExec()).isTrue();

final GenericContainer.ExecResult result = redis.execInContainer("redis-cli", commandParam, "role");
assertThat(result.getStdout())
.as("Output for \"redis-cli role\" command should start with \"master\"")
.startsWith("master");
assertThat(result.getStderr()).as("Stderr for \"redis-cli role\" command should be empty").isEmpty();
}

@Test
void shouldExecuteCommandWithUser() throws Exception {
// The older "lxc" execution driver doesn't support "exec". At the time of writing (2016/03/29),
Expand Down
Loading