mirror of
https://github.com/floci-io/floci-cli.git
synced 2026-11-22 21:50:47 -05:00
fix(cli): keep the next step when an error's cause has several lines
A failed docker run with more than one line of output lost its 'floci doctor' hint, and a profile or Compose file that does not parse was reported with the parser's source-location line instead of what to do. Causes are now shown as one line, and docker's own output always gets its next step. Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
12 files changed
+147
-26
No files matched your search
@@ -11,6 +11,8 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.DisabledOnOs;
|
||||
import org.junit.jupiter.api.condition.OS;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -66,7 +68,7 @@ class StartPreflightTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String startContainer(List<String> args) {
|
||||
public String startContainer(List<String> args) throws DockerException {
|
||||
runArgs.addAll(args);
|
||||
calls.add("run");
|
||||
return "0123456789abcdef";
|
||||
@@ -272,6 +274,29 @@ class StartPreflightTest {
|
||||
assertEquals(List.of(), docker.calls);
|
||||
}
|
||||
|
||||
/**
|
||||
* BL-096: docker's own error is often several lines. The next step must still follow it; a
|
||||
* second line of docker output is not advice.
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"docker: Error response from daemon: driver failed programming external connectivity.",
|
||||
"docker: Error response from daemon: Conflict.\nRun 'docker run --help' for more information.\n"})
|
||||
void aFailedDockerRunKeepsItsNextStep(String dockerOutput) {
|
||||
FakeDocker docker = new FakeDocker(REMOTE) {
|
||||
@Override
|
||||
public String startContainer(List<String> args) throws DockerException {
|
||||
throw DockerException.ofOutput(dockerOutput);
|
||||
}
|
||||
};
|
||||
|
||||
Out r = start(docker, "--container", "floci-gcp-preflight", "--detach");
|
||||
|
||||
assertEquals(1, r.exit());
|
||||
assertTrue(r.err().contains("Failed to start container: docker: Error response from daemon"), r.err());
|
||||
assertTrue(r.err().strip().endsWith("Run 'floci gcp doctor' to check Docker, the image and the port."), r.err());
|
||||
}
|
||||
|
||||
/** A context selected with DOCKER_CONTEXT or 'docker context use' is not in the environment: docker is asked. */
|
||||
@Test
|
||||
@DisabledOnOs(OS.WINDOWS)
|
||||
|
||||
Reference in new issue
Block a user