The cli now doesn't echo the container ID when started using either -a
or -i. Also fixes `TestStartAttachCorrectExitCode` which incorrectly
called start with the result of wait rather than the container ID.
Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com>
| ... | ... |
@@ -707,12 +707,12 @@ func (cli *DockerCli) CmdStart(args ...string) error {
|
| 707 | 707 |
for _, name := range cmd.Args() {
|
| 708 | 708 |
_, _, err := readBody(cli.call("POST", "/containers/"+name+"/start", nil, false))
|
| 709 | 709 |
if err != nil {
|
| 710 |
- if !*attach || !*openStdin {
|
|
| 710 |
+ if !*attach && !*openStdin {
|
|
| 711 | 711 |
fmt.Fprintf(cli.err, "%s\n", err) |
| 712 | 712 |
} |
| 713 | 713 |
encounteredError = fmt.Errorf("Error: failed to start one or more containers")
|
| 714 | 714 |
} else {
|
| 715 |
- if !*attach || !*openStdin {
|
|
| 715 |
+ if !*attach && !*openStdin {
|
|
| 716 | 716 |
fmt.Fprintf(cli.out, "%s\n", name) |
| 717 | 717 |
} |
| 718 | 718 |
} |
| ... | ... |
@@ -53,8 +53,8 @@ func TestStartAttachCorrectExitCode(t *testing.T) {
|
| 53 | 53 |
|
| 54 | 54 |
// make sure the container has exited before trying the "start -a" |
| 55 | 55 |
waitCmd := exec.Command(dockerBinary, "wait", out) |
| 56 |
- if out, _, err = runCommandWithOutput(waitCmd); err != nil {
|
|
| 57 |
- t.Fatal(out, err) |
|
| 56 |
+ if _, _, err = runCommandWithOutput(waitCmd); err != nil {
|
|
| 57 |
+ t.Fatalf("Failed to wait on container: %v", err)
|
|
| 58 | 58 |
} |
| 59 | 59 |
|
| 60 | 60 |
startCmd := exec.Command(dockerBinary, "start", "-a", out) |
| ... | ... |
@@ -69,6 +69,34 @@ func TestStartAttachCorrectExitCode(t *testing.T) {
|
| 69 | 69 |
logDone("start - correct exit code returned with -a")
|
| 70 | 70 |
} |
| 71 | 71 |
|
| 72 |
+func TestStartSilentAttach(t *testing.T) {
|
|
| 73 |
+ defer deleteAllContainers() |
|
| 74 |
+ |
|
| 75 |
+ name := "teststartattachcorrectexitcode" |
|
| 76 |
+ runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "echo", "test") |
|
| 77 |
+ out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
| 78 |
+ if err != nil {
|
|
| 79 |
+ t.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 80 |
+ } |
|
| 81 |
+ |
|
| 82 |
+ // make sure the container has exited before trying the "start -a" |
|
| 83 |
+ waitCmd := exec.Command(dockerBinary, "wait", name) |
|
| 84 |
+ if _, _, err = runCommandWithOutput(waitCmd); err != nil {
|
|
| 85 |
+ t.Fatalf("wait command failed with error: %v", err)
|
|
| 86 |
+ } |
|
| 87 |
+ |
|
| 88 |
+ startCmd := exec.Command(dockerBinary, "start", "-a", name) |
|
| 89 |
+ startOut, _, err := runCommandWithOutput(startCmd) |
|
| 90 |
+ if err != nil {
|
|
| 91 |
+ t.Fatalf("start command failed unexpectedly with error: %v, output: %q", err, startOut)
|
|
| 92 |
+ } |
|
| 93 |
+ if expected := "test\n"; startOut != expected {
|
|
| 94 |
+ t.Fatalf("start -a produced unexpected output: expected %q, got %q", expected, startOut)
|
|
| 95 |
+ } |
|
| 96 |
+ |
|
| 97 |
+ logDone("start - don't echo container ID when attaching")
|
|
| 98 |
+} |
|
| 99 |
+ |
|
| 72 | 100 |
func TestStartRecordError(t *testing.T) {
|
| 73 | 101 |
defer deleteAllContainers() |
| 74 | 102 |
|