|
@@ -14,6 +14,7 @@ import (
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/pkg/stringid"
|
|
"github.com/docker/docker/pkg/stringid"
|
|
|
|
+ "github.com/docker/docker/runconfig"
|
|
"github.com/go-check/check"
|
|
"github.com/go-check/check"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -676,43 +677,97 @@ func (s *DockerSuite) TestContainerApiCreate(c *check.C) {
|
|
}
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestContainerApiCreateWithHostName(c *check.C) {
|
|
func (s *DockerSuite) TestContainerApiCreateWithHostName(c *check.C) {
|
|
- var hostName = "test-host"
|
|
|
|
|
|
+ hostName := "test-host"
|
|
config := map[string]interface{}{
|
|
config := map[string]interface{}{
|
|
"Image": "busybox",
|
|
"Image": "busybox",
|
|
"Hostname": hostName,
|
|
"Hostname": hostName,
|
|
}
|
|
}
|
|
|
|
|
|
- _, b, err := sockRequest("POST", "/containers/create", config)
|
|
|
|
- if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
|
|
|
|
|
|
+ status, body, err := sockRequest("POST", "/containers/create", config)
|
|
|
|
+ c.Assert(err, check.IsNil)
|
|
|
|
+ c.Assert(status, check.Equals, http.StatusCreated)
|
|
|
|
+
|
|
|
|
+ var container types.ContainerCreateResponse
|
|
|
|
+ if err := json.Unmarshal(body, &container); err != nil {
|
|
c.Fatal(err)
|
|
c.Fatal(err)
|
|
}
|
|
}
|
|
- type createResp struct {
|
|
|
|
- Id string
|
|
|
|
|
|
+
|
|
|
|
+ status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
|
|
|
+ c.Assert(err, check.IsNil)
|
|
|
|
+ c.Assert(status, check.Equals, http.StatusOK)
|
|
|
|
+
|
|
|
|
+ var containerJSON types.ContainerJSON
|
|
|
|
+ if err := json.Unmarshal(body, &containerJSON); err != nil {
|
|
|
|
+ c.Fatal(err)
|
|
}
|
|
}
|
|
- var container createResp
|
|
|
|
- if err := json.Unmarshal(b, &container); err != nil {
|
|
|
|
|
|
+
|
|
|
|
+ if containerJSON.Config.Hostname != hostName {
|
|
|
|
+ c.Fatalf("Mismatched Hostname, Expected %s, Actual: %s ", hostName, containerJSON.Config.Hostname)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (s *DockerSuite) TestContainerApiCreateWithDomainName(c *check.C) {
|
|
|
|
+ domainName := "test-domain"
|
|
|
|
+ config := map[string]interface{}{
|
|
|
|
+ "Image": "busybox",
|
|
|
|
+ "Domainname": domainName,
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ status, body, err := sockRequest("POST", "/containers/create", config)
|
|
|
|
+ c.Assert(err, check.IsNil)
|
|
|
|
+ c.Assert(status, check.Equals, http.StatusCreated)
|
|
|
|
+
|
|
|
|
+ var container types.ContainerCreateResponse
|
|
|
|
+ if err := json.Unmarshal(body, &container); err != nil {
|
|
|
|
+ c.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
|
|
|
+ c.Assert(err, check.IsNil)
|
|
|
|
+ c.Assert(status, check.Equals, http.StatusOK)
|
|
|
|
+
|
|
|
|
+ var containerJSON types.ContainerJSON
|
|
|
|
+ if err := json.Unmarshal(body, &containerJSON); err != nil {
|
|
c.Fatal(err)
|
|
c.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- var id = container.Id
|
|
|
|
|
|
+ if containerJSON.Config.Domainname != domainName {
|
|
|
|
+ c.Fatalf("Mismatched Domainname, Expected %s, Actual: %s ", domainName, containerJSON.Config.Domainname)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
- _, bodyGet, err := sockRequest("GET", "/containers/"+id+"/json", nil)
|
|
|
|
|
|
+func (s *DockerSuite) TestContainerApiCreateNetworkMode(c *check.C) {
|
|
|
|
+ UtilCreateNetworkMode(c, "host")
|
|
|
|
+ UtilCreateNetworkMode(c, "bridge")
|
|
|
|
+ UtilCreateNetworkMode(c, "container:web1")
|
|
|
|
+}
|
|
|
|
|
|
- type configLocal struct {
|
|
|
|
- Hostname string
|
|
|
|
|
|
+func UtilCreateNetworkMode(c *check.C, networkMode string) {
|
|
|
|
+ config := map[string]interface{}{
|
|
|
|
+ "Image": "busybox",
|
|
|
|
+ "HostConfig": map[string]interface{}{"NetworkMode": networkMode},
|
|
}
|
|
}
|
|
- type getResponse struct {
|
|
|
|
- Id string
|
|
|
|
- Config configLocal
|
|
|
|
|
|
+
|
|
|
|
+ status, body, err := sockRequest("POST", "/containers/create", config)
|
|
|
|
+ c.Assert(err, check.IsNil)
|
|
|
|
+ c.Assert(status, check.Equals, http.StatusCreated)
|
|
|
|
+
|
|
|
|
+ var container types.ContainerCreateResponse
|
|
|
|
+ if err := json.Unmarshal(body, &container); err != nil {
|
|
|
|
+ c.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- var containerInfo getResponse
|
|
|
|
- if err := json.Unmarshal(bodyGet, &containerInfo); err != nil {
|
|
|
|
|
|
+ status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
|
|
|
+ c.Assert(err, check.IsNil)
|
|
|
|
+ c.Assert(status, check.Equals, http.StatusOK)
|
|
|
|
+
|
|
|
|
+ var containerJSON types.ContainerJSON
|
|
|
|
+ if err := json.Unmarshal(body, &containerJSON); err != nil {
|
|
c.Fatal(err)
|
|
c.Fatal(err)
|
|
}
|
|
}
|
|
- var hostNameActual = containerInfo.Config.Hostname
|
|
|
|
- if hostNameActual != "test-host" {
|
|
|
|
- c.Fatalf("Mismatched Hostname, Expected %v, Actual: %v ", hostName, hostNameActual)
|
|
|
|
|
|
+
|
|
|
|
+ if containerJSON.HostConfig.NetworkMode != runconfig.NetworkMode(networkMode) {
|
|
|
|
+ c.Fatalf("Mismatched NetworkMode, Expected %s, Actual: %s ", networkMode, containerJSON.HostConfig.NetworkMode)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|