浏览代码

add tests

Docker-DCO-1.1-Signed-off-by: Victor Vieux <vieux@docker.com> (github: vieux)
Victor Vieux 11 年之前
父节点
当前提交
fc39f9c78d
共有 1 个文件被更改,包括 81 次插入0 次删除
  1. 81 0
      integration-cli/docker_cli_run_test.go

+ 81 - 0
integration-cli/docker_cli_run_test.go

@@ -1549,3 +1549,84 @@ func TestRunExitOnStdinClose(t *testing.T) {
 	}
 	logDone("run - exit on stdin closing")
 }
+
+// Test for #2267
+func TestWriteHostsFileAndNotCommit(t *testing.T) {
+	name := "writehosts"
+	cmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo test2267 >> /etc/hosts && cat /etc/hosts")
+	out, _, err := runCommandWithOutput(cmd)
+	if err != nil {
+		t.Fatal(err, out)
+	}
+	if !strings.Contains(out, "test2267") {
+		t.Fatal("/etc/hosts should contain 'test2267'")
+	}
+
+	cmd = exec.Command(dockerBinary, "diff", name)
+	if err != nil {
+		t.Fatal(err, out)
+	}
+	out, _, err = runCommandWithOutput(cmd)
+	if err != nil {
+		t.Fatal(err, out)
+	}
+	if len(strings.Trim(out, "\r\n")) != 0 {
+		t.Fatal("diff should be empty")
+	}
+
+	logDone("run - write to /etc/hosts and not commited")
+}
+
+// Test for #2267
+func TestWriteHostnameFileAndNotCommit(t *testing.T) {
+	name := "writehostname"
+	cmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo test2267 >> /etc/hostname && cat /etc/hostname")
+	out, _, err := runCommandWithOutput(cmd)
+	if err != nil {
+		t.Fatal(err, out)
+	}
+	if !strings.Contains(out, "test2267") {
+		t.Fatal("/etc/hostname should contain 'test2267'")
+	}
+
+	cmd = exec.Command(dockerBinary, "diff", name)
+	if err != nil {
+		t.Fatal(err, out)
+	}
+	out, _, err = runCommandWithOutput(cmd)
+	if err != nil {
+		t.Fatal(err, out)
+	}
+	if len(strings.Trim(out, "\r\n")) != 0 {
+		t.Fatal("diff should be empty")
+	}
+
+	logDone("run - write to /etc/hostname and not commited")
+}
+
+// Test for #2267
+func TestWriteResolvFileAndNotCommit(t *testing.T) {
+	name := "writeresolv"
+	cmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo test2267 >> /etc/resolv.conf && cat /etc/resolv.conf")
+	out, _, err := runCommandWithOutput(cmd)
+	if err != nil {
+		t.Fatal(err, out)
+	}
+	if !strings.Contains(out, "test2267") {
+		t.Fatal("/etc/resolv.conf should contain 'test2267'")
+	}
+
+	cmd = exec.Command(dockerBinary, "diff", name)
+	if err != nil {
+		t.Fatal(err, out)
+	}
+	out, _, err = runCommandWithOutput(cmd)
+	if err != nil {
+		t.Fatal(err, out)
+	}
+	if len(strings.Trim(out, "\r\n")) != 0 {
+		t.Fatal("diff should be empty")
+	}
+
+	logDone("run - write to /etc/resolv.conf and not commited")
+}