Merge pull request #13069 from runcom/dry-run-test

API tests - Container create with Hostname, Domainname and Network
This commit is contained in:
Brian Goff 2015-05-07 22:07:41 -04:00
Родитель fe3becee34 80d73c838a
Коммит af9dac9627
1 изменённых файлов: 81 добавлений и 26 удалений

Просмотреть файл

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