Browse code

Merge pull request #12690 from rajdeepd/dry-run-test

Container API Test with HostName

Jessie Frazelle authored on 2015/04/24 03:32:47
Showing 1 changed files
... ...
@@ -681,6 +681,47 @@ func (s *DockerSuite) TestContainerApiCreate(c *check.C) {
681 681
 	}
682 682
 }
683 683
 
684
+func (s *DockerSuite) TestContainerApiCreateWithHostName(c *check.C) {
685
+	var hostName = "test-host"
686
+	config := map[string]interface{}{
687
+		"Image":    "busybox",
688
+		"Hostname": hostName,
689
+	}
690
+
691
+	_, b, err := sockRequest("POST", "/containers/create", config)
692
+	if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
693
+		c.Fatal(err)
694
+	}
695
+	type createResp struct {
696
+		Id string
697
+	}
698
+	var container createResp
699
+	if err := json.Unmarshal(b, &container); err != nil {
700
+		c.Fatal(err)
701
+	}
702
+
703
+	var id = container.Id
704
+
705
+	_, bodyGet, err := sockRequest("GET", "/containers/"+id+"/json", nil)
706
+
707
+	type configLocal struct {
708
+		Hostname string
709
+	}
710
+	type getResponse struct {
711
+		Id     string
712
+		Config configLocal
713
+	}
714
+
715
+	var containerInfo getResponse
716
+	if err := json.Unmarshal(bodyGet, &containerInfo); err != nil {
717
+		c.Fatal(err)
718
+	}
719
+	var hostNameActual = containerInfo.Config.Hostname
720
+	if hostNameActual != "test-host" {
721
+		c.Fatalf("Mismatched Hostname, Expected %v, Actual: %v ", hostName, hostNameActual)
722
+	}
723
+}
724
+
684 725
 func (s *DockerSuite) TestContainerApiVerifyHeader(c *check.C) {
685 726
 	config := map[string]interface{}{
686 727
 		"Image": "busybox",