diff --git a/integration-cli/docker_cli_kill_test.go b/integration-cli/docker_cli_kill_test.go index b8265d8cfb..6ee246f5ff 100644 --- a/integration-cli/docker_cli_kill_test.go +++ b/integration-cli/docker_cli_kill_test.go @@ -34,3 +34,31 @@ func TestKillContainer(t *testing.T) { logDone("kill - kill container running sleep 10") } + +func TestKillDifferentUserContainer(t *testing.T) { + runCmd := exec.Command(dockerBinary, "run", "-u", "daemon", "-d", "busybox", "sh", "-c", "sleep 10") + out, _, err := runCommandWithOutput(runCmd) + errorOut(err, t, fmt.Sprintf("run failed with errors: %v", err)) + + cleanedContainerID := stripTrailingCharacters(out) + + inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID) + inspectOut, _, err := runCommandWithOutput(inspectCmd) + errorOut(err, t, fmt.Sprintf("out should've been a container id: %v %v", inspectOut, err)) + + killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID) + out, _, err = runCommandWithOutput(killCmd) + errorOut(err, t, fmt.Sprintf("failed to kill container: %v %v", out, err)) + + listRunningContainersCmd := exec.Command(dockerBinary, "ps", "-q") + out, _, err = runCommandWithOutput(listRunningContainersCmd) + errorOut(err, t, fmt.Sprintf("failed to list running containers: %v", err)) + + if strings.Contains(out, cleanedContainerID) { + t.Fatal("killed container is still running") + } + + deleteContainer(cleanedContainerID) + + logDone("kill - kill container running sleep 10 from a different user") +} diff --git a/integration/container_test.go b/integration/container_test.go index 4462aba08d..9d55b0b365 100644 --- a/integration/container_test.go +++ b/integration/container_test.go @@ -13,64 +13,6 @@ import ( "github.com/docker/docker/runconfig" ) -func TestKillDifferentUser(t *testing.T) { - daemon := mkDaemon(t) - defer nuke(daemon) - - container, _, err := daemon.Create(&runconfig.Config{ - Image: GetTestImage(daemon).ID, - Cmd: []string{"cat"}, - OpenStdin: true, - User: "daemon", - }, - "", - ) - if err != nil { - t.Fatal(err) - } - defer daemon.Destroy(container) - // FIXME @shykes: this seems redundant, but is very old, I'm leaving it in case - // there is a side effect I'm not seeing. - // defer container.stdin.Close() - - if container.State.IsRunning() { - t.Errorf("Container shouldn't be running") - } - if err := container.Start(); err != nil { - t.Fatal(err) - } - - setTimeout(t, "Waiting for the container to be started timed out", 2*time.Second, func() { - for !container.State.IsRunning() { - time.Sleep(10 * time.Millisecond) - } - }) - - setTimeout(t, "read/write assertion timed out", 2*time.Second, func() { - out, _ := container.StdoutPipe() - in, _ := container.StdinPipe() - if err := assertPipe("hello\n", "hello", out, in, 150); err != nil { - t.Fatal(err) - } - }) - - if err := container.Kill(); err != nil { - t.Fatal(err) - } - - if container.State.IsRunning() { - t.Errorf("Container shouldn't be running") - } - container.State.WaitStop(-1 * time.Second) - if container.State.IsRunning() { - t.Errorf("Container shouldn't be running") - } - // Try stopping twice - if err := container.Kill(); err != nil { - t.Fatal(err) - } -} - func TestRestartStdin(t *testing.T) { daemon := mkDaemon(t) defer nuke(daemon)