Ver Fonte

move TestKillDifferentUser

Signed-off-by: Victor Vieux <vieux@docker.com>
Victor Vieux há 11 anos atrás
pai
commit
eb9379c5d0
2 ficheiros alterados com 28 adições e 58 exclusões
  1. 28 0
      integration-cli/docker_cli_kill_test.go
  2. 0 58
      integration/container_test.go

+ 28 - 0
integration-cli/docker_cli_kill_test.go

@@ -34,3 +34,31 @@ func TestKillContainer(t *testing.T) {
 
 
 	logDone("kill - kill container running sleep 10")
 	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")
+}

+ 0 - 58
integration/container_test.go

@@ -13,64 +13,6 @@ import (
 	"github.com/docker/docker/runconfig"
 	"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) {
 func TestRestartStdin(t *testing.T) {
 	daemon := mkDaemon(t)
 	daemon := mkDaemon(t)
 	defer nuke(daemon)
 	defer nuke(daemon)