Quellcode durchsuchen

Add tests for create /etc volume

Signed-off-by: Lei Jitang <leijitang@huawei.com>
Lei Jitang vor 10 Jahren
Ursprung
Commit
f3713010dd
1 geänderte Dateien mit 35 neuen und 0 gelöschten Zeilen
  1. 35 0
      integration-cli/docker_cli_run_test.go

+ 35 - 0
integration-cli/docker_cli_run_test.go

@@ -2476,6 +2476,41 @@ func TestRunReuseBindVolumeThatIsSymlink(t *testing.T) {
 	logDone("run - can remount old bindmount volume")
 }
 
+//test create /etc volume
+func TestRunCreateVolumeEtc(t *testing.T) {
+	cmd := exec.Command(dockerBinary, "run", "--dns=127.0.0.1", "-v", "/etc", "busybox", "cat", "/etc/resolv.conf")
+	out, _, err := runCommandWithOutput(cmd)
+	if err != nil {
+		t.Fatal("failed to run container: %v, output: %q", err, out)
+	}
+	if !strings.Contains(out, "nameserver 127.0.0.1") {
+		t.Fatal("failed: create /etc volume cover /etc/resolv.conf")
+	}
+
+	cmd = exec.Command(dockerBinary, "run", "-h=test123", "-v", "/etc", "busybox", "cat", "/etc/hostname")
+	out, _, err = runCommandWithOutput(cmd)
+	if err != nil {
+		t.Fatal("failed to run container: %v, output: %q", err, out)
+	}
+	if !strings.Contains(out, "test123") {
+		t.Fatal("failed: create /etc volume cover /etc/hostname")
+	}
+
+	cmd = exec.Command(dockerBinary, "run", "--add-host=test:192.168.0.1", "-v", "/etc", "busybox", "cat", "/etc/hosts")
+	out, _, err = runCommandWithOutput(cmd)
+	if err != nil {
+		t.Fatal("failed to run container: %v, output: %q", err, out)
+	}
+	out = strings.Replace(out, "\n", " ", -1)
+	if !strings.Contains(out, "192.168.0.1"+"\t"+"test") || !strings.Contains(out, "127.0.0.1"+"\t"+"localhost") {
+		t.Fatal("failed: create /etc volume cover /etc/hosts", out)
+	}
+
+	deleteAllContainers()
+
+	logDone("run - create /etc volume success")
+}
+
 func TestVolumesNoCopyData(t *testing.T) {
 	defer deleteImages("dataimage")
 	defer deleteAllContainers()