Переглянути джерело

Add test for --pid=host

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
Michael Crosby 10 роки тому
батько
коміт
15e8f3fdd3
1 змінених файлів з 32 додано та 0 видалено
  1. 32 0
      integration-cli/docker_cli_run_test.go

+ 32 - 0
integration-cli/docker_cli_run_test.go

@@ -2750,6 +2750,38 @@ func TestContainerNetworkMode(t *testing.T) {
 	logDone("run - container shared network namespace")
 	logDone("run - container shared network namespace")
 }
 }
 
 
+func TestRunModePidHost(t *testing.T) {
+	hostPid, err := os.Readlink("/proc/1/ns/pid")
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	cmd := exec.Command(dockerBinary, "run", "--pid=host", "busybox", "readlink", "/proc/self/ns/pid")
+	out2, _, err := runCommandWithOutput(cmd)
+	if err != nil {
+		t.Fatal(err, out2)
+	}
+
+	out2 = strings.Trim(out2, "\n")
+	if hostPid != out2 {
+		t.Fatalf("PID different with --pid=host %s != %s\n", hostPid, out2)
+	}
+
+	cmd = exec.Command(dockerBinary, "run", "busybox", "readlink", "/proc/self/ns/pid")
+	out2, _, err = runCommandWithOutput(cmd)
+	if err != nil {
+		t.Fatal(err, out2)
+	}
+
+	out2 = strings.Trim(out2, "\n")
+	if hostPid == out2 {
+		t.Fatalf("PID should be different without --pid=host %s == %s\n", hostPid, out2)
+	}
+	deleteAllContainers()
+
+	logDone("run - pid host mode")
+}
+
 func TestRunTLSverify(t *testing.T) {
 func TestRunTLSverify(t *testing.T) {
 	cmd := exec.Command(dockerBinary, "ps")
 	cmd := exec.Command(dockerBinary, "ps")
 	out, ec, err := runCommandWithOutput(cmd)
 	out, ec, err := runCommandWithOutput(cmd)