1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #18198 from aditirajagopal/16756-docker_api_inspect_test

Checkers on docker_api_inspect_test.go
This commit is contained in:
Vincent Demeester 2015-12-01 09:56:01 +01:00
commit 657085dfdb

View file

@ -32,20 +32,17 @@ func (s *DockerSuite) TestInspectApiContainerResponse(c *check.C) {
body := getInspectBody(c, cs.version, cleanedContainerID)
var inspectJSON map[string]interface{}
if err := json.Unmarshal(body, &inspectJSON); err != nil {
c.Fatalf("unable to unmarshal body for version %s: %v", cs.version, err)
}
err := json.Unmarshal(body, &inspectJSON)
c.Assert(err, checker.IsNil, check.Commentf("Unable to unmarshal body for version %s", cs.version))
for _, key := range cs.keys {
if _, ok := inspectJSON[key]; !ok {
c.Fatalf("%s does not exist in response for version %s", key, cs.version)
}
_, ok := inspectJSON[key]
c.Check(ok, checker.True, check.Commentf("%s does not exist in response for version %s", key, cs.version))
}
//Issue #6830: type not properly converted to JSON/back
if _, ok := inspectJSON["Path"].(bool); ok {
c.Fatalf("Path of `true` should not be converted to boolean `true` via JSON marshalling")
}
_, ok := inspectJSON["Path"].(bool)
c.Assert(ok, checker.False, check.Commentf("Path of `true` should not be converted to boolean `true` via JSON marshalling"))
}
}
@ -59,18 +56,14 @@ func (s *DockerSuite) TestInspectApiContainerVolumeDriverLegacy(c *check.C) {
body := getInspectBody(c, version, cleanedContainerID)
var inspectJSON map[string]interface{}
if err := json.Unmarshal(body, &inspectJSON); err != nil {
c.Fatalf("unable to unmarshal body for version %s: %v", version, err)
}
err := json.Unmarshal(body, &inspectJSON)
c.Assert(err, checker.IsNil, check.Commentf("Unable to unmarshal body for version %s", version))
config, ok := inspectJSON["Config"]
if !ok {
c.Fatal("Unable to find 'Config'")
}
c.Assert(ok, checker.True, check.Commentf("Unable to find 'Config'"))
cfg := config.(map[string]interface{})
if _, ok := cfg["VolumeDriver"]; !ok {
c.Fatalf("Api version %s expected to include VolumeDriver in 'Config'", version)
}
_, ok = cfg["VolumeDriver"]
c.Assert(ok, checker.True, check.Commentf("Api version %s expected to include VolumeDriver in 'Config'", version))
}
}
@ -82,27 +75,20 @@ func (s *DockerSuite) TestInspectApiContainerVolumeDriver(c *check.C) {
body := getInspectBody(c, "v1.21", cleanedContainerID)
var inspectJSON map[string]interface{}
if err := json.Unmarshal(body, &inspectJSON); err != nil {
c.Fatalf("unable to unmarshal body for version 1.21: %v", err)
}
err := json.Unmarshal(body, &inspectJSON)
c.Assert(err, checker.IsNil, check.Commentf("Unable to unmarshal body for version 1.21"))
config, ok := inspectJSON["Config"]
if !ok {
c.Fatal("Unable to find 'Config'")
}
c.Assert(ok, checker.True, check.Commentf("Unable to find 'Config'"))
cfg := config.(map[string]interface{})
if _, ok := cfg["VolumeDriver"]; ok {
c.Fatal("Api version 1.21 expected to not include VolumeDriver in 'Config'")
}
_, ok = cfg["VolumeDriver"]
c.Assert(ok, checker.False, check.Commentf("Api version 1.21 expected to not include VolumeDriver in 'Config'"))
config, ok = inspectJSON["HostConfig"]
if !ok {
c.Fatal("Unable to find 'HostConfig'")
}
c.Assert(ok, checker.True, check.Commentf("Unable to find 'Config'"))
cfg = config.(map[string]interface{})
if _, ok := cfg["VolumeDriver"]; !ok {
c.Fatal("Api version 1.21 expected to include VolumeDriver in 'HostConfig'")
}
_, ok = cfg["VolumeDriver"]
c.Assert(ok, checker.True, check.Commentf("Api version 1.21 expected to include VolumeDriver in 'HostConfig'"))
}
func (s *DockerSuite) TestInspectApiImageResponse(c *check.C) {
@ -111,18 +97,16 @@ func (s *DockerSuite) TestInspectApiImageResponse(c *check.C) {
endpoint := "/images/busybox/json"
status, body, err := sockRequest("GET", endpoint, nil)
c.Assert(err, check.IsNil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusOK)
var imageJSON types.ImageInspect
if err = json.Unmarshal(body, &imageJSON); err != nil {
c.Fatalf("unable to unmarshal body for latest version: %v", err)
}
err = json.Unmarshal(body, &imageJSON)
c.Assert(err, checker.IsNil, check.Commentf("Unable to unmarshal body for latest version"))
c.Assert(imageJSON.RepoTags, checker.HasLen, 2)
c.Assert(len(imageJSON.RepoTags), check.Equals, 2)
c.Assert(stringutils.InSlice(imageJSON.RepoTags, "busybox:latest"), check.Equals, true)
c.Assert(stringutils.InSlice(imageJSON.RepoTags, "busybox:mytag"), check.Equals, true)
c.Assert(stringutils.InSlice(imageJSON.RepoTags, "busybox:latest"), checker.Equals, true)
c.Assert(stringutils.InSlice(imageJSON.RepoTags, "busybox:mytag"), checker.Equals, true)
}
// #17131, #17139, #17173
@ -136,19 +120,14 @@ func (s *DockerSuite) TestInspectApiEmptyFieldsInConfigPre121(c *check.C) {
body := getInspectBody(c, version, cleanedContainerID)
var inspectJSON map[string]interface{}
if err := json.Unmarshal(body, &inspectJSON); err != nil {
c.Fatalf("unable to unmarshal body for version %s: %v", version, err)
}
err := json.Unmarshal(body, &inspectJSON)
c.Assert(err, checker.IsNil, check.Commentf("Unable to unmarshal body for version %s", version))
config, ok := inspectJSON["Config"]
if !ok {
c.Fatal("Unable to find 'Config'")
}
c.Assert(ok, checker.True, check.Commentf("Unable to find 'Config'"))
cfg := config.(map[string]interface{})
for _, f := range []string{"MacAddress", "NetworkDisabled", "ExposedPorts"} {
if _, ok := cfg[f]; !ok {
c.Fatalf("Api version %s expected to include %s in 'Config'", version, f)
}
_, ok := cfg[f]
c.Check(ok, checker.True, check.Commentf("Api version %s expected to include %s in 'Config'", version, f))
}
}
}