Browse code

add test

Docker-DCO-1.1-Signed-off-by: Victor Vieux <vieux@docker.com> (github: vieux)

Victor Vieux authored on 2014/06/13 04:11:51
Showing 1 changed files
... ...
@@ -885,3 +885,34 @@ func TestRunUnprivilegedWithChroot(t *testing.T) {
885 885
 
886 886
 	logDone("run - unprivileged with chroot")
887 887
 }
888
+
889
+func TestModeHostname(t *testing.T) {
890
+	cmd := exec.Command(dockerBinary, "run", "-h=testhostname", "busybox", "cat", "/etc/hostname")
891
+
892
+	out, _, err := runCommandWithOutput(cmd)
893
+	if err != nil {
894
+		t.Fatal(err, out)
895
+	}
896
+
897
+	if actual := strings.Trim(out, "\r\n"); actual != "testhostname" {
898
+		t.Fatalf("expected 'testhostname', but says: '%s'", actual)
899
+	}
900
+
901
+	cmd = exec.Command(dockerBinary, "run", "--net=host", "busybox", "cat", "/etc/hostname")
902
+
903
+	out, _, err = runCommandWithOutput(cmd)
904
+	if err != nil {
905
+		t.Fatal(err, out)
906
+	}
907
+	hostname, err := os.Hostname()
908
+	if err != nil {
909
+		t.Fatal(err)
910
+	}
911
+	if actual := strings.Trim(out, "\r\n"); actual != hostname {
912
+		t.Fatalf("expected '%s', but says: '%s'", hostname, actual)
913
+	}
914
+
915
+	deleteAllContainers()
916
+
917
+	logDone("run - hostname and several network modes")
918
+}