|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "fmt" |
4 | 5 | "os/exec" |
| 6 | + "strings" |
5 | 7 | "testing" |
6 | 8 | "time" |
7 | 9 | ) |
@@ -36,3 +38,33 @@ func TestStartAttachReturnsOnError(t *testing.T) { |
36 | 38 |
|
37 | 39 | logDone("start - error on start with attach exits") |
38 | 40 | } |
| 41 | + |
| 42 | +// gh#8555: Exit code should be passed through when using start -a |
| 43 | +func TestStartAttachCorrectExitCode(t *testing.T) { |
| 44 | + defer deleteAllContainers() |
| 45 | + |
| 46 | + runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "sleep 2; exit 1") |
| 47 | + out, _, _, err := runCommandWithStdoutStderr(runCmd) |
| 48 | + if err != nil { |
| 49 | + t.Fatalf("failed to run container: %v, output: %q", err, out) |
| 50 | + } |
| 51 | + |
| 52 | + out = stripTrailingCharacters(out) |
| 53 | + |
| 54 | + // make sure the container has exited before trying the "start -a" |
| 55 | + waitCmd := exec.Command(dockerBinary, "wait", out) |
| 56 | + if out, _, err = runCommandWithOutput(waitCmd); err != nil { |
| 57 | + t.Fatal(out, err) |
| 58 | + } |
| 59 | + |
| 60 | + startCmd := exec.Command(dockerBinary, "start", "-a", out) |
| 61 | + startOut, exitCode, err := runCommandWithOutput(startCmd) |
| 62 | + if err != nil && !strings.Contains("exit status 1", fmt.Sprintf("%s", err)) { |
| 63 | + t.Fatalf("start command failed unexpectedly with error: %v, output: %q", err, startOut) |
| 64 | + } |
| 65 | + if exitCode != 1 { |
| 66 | + t.Fatalf("start -a did not respond with proper exit code: expected 1, got %d", exitCode) |
| 67 | + } |
| 68 | + |
| 69 | + logDone("start - correct exit code returned with -a") |
| 70 | +} |
0 commit comments