|
@@ -240,3 +240,49 @@ func TestStartMultipleContainers(t *testing.T) {
|
|
|
|
|
|
logDone("start - start multiple containers continue on one failed")
|
|
|
}
|
|
|
+
|
|
|
+func TestStartAttachMultipleContainers(t *testing.T) {
|
|
|
+
|
|
|
+ var cmd *exec.Cmd
|
|
|
+
|
|
|
+ defer deleteAllContainers()
|
|
|
+ // run multiple containers to test
|
|
|
+ for _, container := range []string{"test1", "test2", "test3"} {
|
|
|
+ cmd = exec.Command(dockerBinary, "run", "-d", "--name", container, "busybox", "top")
|
|
|
+ if out, _, err := runCommandWithOutput(cmd); err != nil {
|
|
|
+ t.Fatal(out, err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // stop all the containers
|
|
|
+ for _, container := range []string{"test1", "test2", "test3"} {
|
|
|
+ cmd = exec.Command(dockerBinary, "stop", container)
|
|
|
+ if out, _, err := runCommandWithOutput(cmd); err != nil {
|
|
|
+ t.Fatal(out, err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // test start and attach multiple containers at once, expected error
|
|
|
+ for _, option := range []string{"-a", "-i", "-ai"} {
|
|
|
+ cmd = exec.Command(dockerBinary, "start", option, "test1", "test2", "test3")
|
|
|
+ out, _, err := runCommandWithOutput(cmd)
|
|
|
+ if !strings.Contains(out, "You cannot start and attach multiple containers at once.") || err == nil {
|
|
|
+ t.Fatal("Expected error but got none")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // confirm the state of all the containers be stopped
|
|
|
+ for container, expected := range map[string]string{"test1": "false", "test2": "false", "test3": "false"} {
|
|
|
+ cmd = exec.Command(dockerBinary, "inspect", "-f", "{{.State.Running}}", container)
|
|
|
+ out, _, err := runCommandWithOutput(cmd)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(out, err)
|
|
|
+ }
|
|
|
+ out = strings.Trim(out, "\r\n")
|
|
|
+ if out != expected {
|
|
|
+ t.Fatal("Container running state wrong")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ logDone("start - error on start and attach multiple containers at once")
|
|
|
+}
|