Browse code

Checkers on docker_api_inspect_test.go

Applying #16756 to integration-cli/docker_api_inspect_test.go

Signed-off-by: Aditi Rajagopal <arajagopal@us.ibm.com>

Aditi Rajagopal authored on 2015/11/25 02:24:27
Showing 1 changed files
... ...
@@ -32,20 +32,17 @@ func (s *DockerSuite) TestInspectApiContainerResponse(c *check.C) {
32 32
 		body := getInspectBody(c, cs.version, cleanedContainerID)
33 33
 
34 34
 		var inspectJSON map[string]interface{}
35
-		if err := json.Unmarshal(body, &inspectJSON); err != nil {
36
-			c.Fatalf("unable to unmarshal body for version %s: %v", cs.version, err)
37
-		}
35
+		err := json.Unmarshal(body, &inspectJSON)
36
+		c.Assert(err, checker.IsNil, check.Commentf("Unable to unmarshal body for version %s", cs.version))
38 37
 
39 38
 		for _, key := range cs.keys {
40
-			if _, ok := inspectJSON[key]; !ok {
41
-				c.Fatalf("%s does not exist in response for version %s", key, cs.version)
42
-			}
39
+			_, ok := inspectJSON[key]
40
+			c.Check(ok, checker.True, check.Commentf("%s does not exist in response for version %s", key, cs.version))
43 41
 		}
44 42
 
45 43
 		//Issue #6830: type not properly converted to JSON/back
46
-		if _, ok := inspectJSON["Path"].(bool); ok {
47
-			c.Fatalf("Path of `true` should not be converted to boolean `true` via JSON marshalling")
48
-		}
44
+		_, ok := inspectJSON["Path"].(bool)
45
+		c.Assert(ok, checker.False, check.Commentf("Path of `true` should not be converted to boolean `true` via JSON marshalling"))
49 46
 	}
50 47
 }
51 48
 
... ...
@@ -59,18 +56,14 @@ func (s *DockerSuite) TestInspectApiContainerVolumeDriverLegacy(c *check.C) {
59 59
 		body := getInspectBody(c, version, cleanedContainerID)
60 60
 
61 61
 		var inspectJSON map[string]interface{}
62
-		if err := json.Unmarshal(body, &inspectJSON); err != nil {
63
-			c.Fatalf("unable to unmarshal body for version %s: %v", version, err)
64
-		}
62
+		err := json.Unmarshal(body, &inspectJSON)
63
+		c.Assert(err, checker.IsNil, check.Commentf("Unable to unmarshal body for version %s", version))
65 64
 
66 65
 		config, ok := inspectJSON["Config"]
67
-		if !ok {
68
-			c.Fatal("Unable to find 'Config'")
69
-		}
66
+		c.Assert(ok, checker.True, check.Commentf("Unable to find 'Config'"))
70 67
 		cfg := config.(map[string]interface{})
71
-		if _, ok := cfg["VolumeDriver"]; !ok {
72
-			c.Fatalf("Api version %s expected to include VolumeDriver in 'Config'", version)
73
-		}
68
+		_, ok = cfg["VolumeDriver"]
69
+		c.Assert(ok, checker.True, check.Commentf("Api version %s expected to include VolumeDriver in 'Config'", version))
74 70
 	}
75 71
 }
76 72
 
... ...
@@ -82,27 +75,20 @@ func (s *DockerSuite) TestInspectApiContainerVolumeDriver(c *check.C) {
82 82
 	body := getInspectBody(c, "v1.21", cleanedContainerID)
83 83
 
84 84
 	var inspectJSON map[string]interface{}
85
-	if err := json.Unmarshal(body, &inspectJSON); err != nil {
86
-		c.Fatalf("unable to unmarshal body for version 1.21: %v", err)
87
-	}
85
+	err := json.Unmarshal(body, &inspectJSON)
86
+	c.Assert(err, checker.IsNil, check.Commentf("Unable to unmarshal body for version 1.21"))
88 87
 
89 88
 	config, ok := inspectJSON["Config"]
90
-	if !ok {
91
-		c.Fatal("Unable to find 'Config'")
92
-	}
89
+	c.Assert(ok, checker.True, check.Commentf("Unable to find 'Config'"))
93 90
 	cfg := config.(map[string]interface{})
94
-	if _, ok := cfg["VolumeDriver"]; ok {
95
-		c.Fatal("Api version 1.21 expected to not include VolumeDriver in 'Config'")
96
-	}
91
+	_, ok = cfg["VolumeDriver"]
92
+	c.Assert(ok, checker.False, check.Commentf("Api version 1.21 expected to not include VolumeDriver in 'Config'"))
97 93
 
98 94
 	config, ok = inspectJSON["HostConfig"]
99
-	if !ok {
100
-		c.Fatal("Unable to find 'HostConfig'")
101
-	}
95
+	c.Assert(ok, checker.True, check.Commentf("Unable to find 'Config'"))
102 96
 	cfg = config.(map[string]interface{})
103
-	if _, ok := cfg["VolumeDriver"]; !ok {
104
-		c.Fatal("Api version 1.21 expected to include VolumeDriver in 'HostConfig'")
105
-	}
97
+	_, ok = cfg["VolumeDriver"]
98
+	c.Assert(ok, checker.True, check.Commentf("Api version 1.21 expected to include VolumeDriver in 'HostConfig'"))
106 99
 }
107 100
 
108 101
 func (s *DockerSuite) TestInspectApiImageResponse(c *check.C) {
... ...
@@ -111,18 +97,16 @@ func (s *DockerSuite) TestInspectApiImageResponse(c *check.C) {
111 111
 	endpoint := "/images/busybox/json"
112 112
 	status, body, err := sockRequest("GET", endpoint, nil)
113 113
 
114
-	c.Assert(err, check.IsNil)
115
-	c.Assert(status, check.Equals, http.StatusOK)
114
+	c.Assert(err, checker.IsNil)
115
+	c.Assert(status, checker.Equals, http.StatusOK)
116 116
 
117 117
 	var imageJSON types.ImageInspect
118
-	if err = json.Unmarshal(body, &imageJSON); err != nil {
119
-		c.Fatalf("unable to unmarshal body for latest version: %v", err)
120
-	}
118
+	err = json.Unmarshal(body, &imageJSON)
119
+	c.Assert(err, checker.IsNil, check.Commentf("Unable to unmarshal body for latest version"))
120
+	c.Assert(imageJSON.RepoTags, checker.HasLen, 2)
121 121
 
122
-	c.Assert(len(imageJSON.RepoTags), check.Equals, 2)
123
-
124
-	c.Assert(stringutils.InSlice(imageJSON.RepoTags, "busybox:latest"), check.Equals, true)
125
-	c.Assert(stringutils.InSlice(imageJSON.RepoTags, "busybox:mytag"), check.Equals, true)
122
+	c.Assert(stringutils.InSlice(imageJSON.RepoTags, "busybox:latest"), checker.Equals, true)
123
+	c.Assert(stringutils.InSlice(imageJSON.RepoTags, "busybox:mytag"), checker.Equals, true)
126 124
 }
127 125
 
128 126
 // #17131, #17139, #17173
... ...
@@ -136,19 +120,14 @@ func (s *DockerSuite) TestInspectApiEmptyFieldsInConfigPre121(c *check.C) {
136 136
 		body := getInspectBody(c, version, cleanedContainerID)
137 137
 
138 138
 		var inspectJSON map[string]interface{}
139
-		if err := json.Unmarshal(body, &inspectJSON); err != nil {
140
-			c.Fatalf("unable to unmarshal body for version %s: %v", version, err)
141
-		}
142
-
139
+		err := json.Unmarshal(body, &inspectJSON)
140
+		c.Assert(err, checker.IsNil, check.Commentf("Unable to unmarshal body for version %s", version))
143 141
 		config, ok := inspectJSON["Config"]
144
-		if !ok {
145
-			c.Fatal("Unable to find 'Config'")
146
-		}
142
+		c.Assert(ok, checker.True, check.Commentf("Unable to find 'Config'"))
147 143
 		cfg := config.(map[string]interface{})
148 144
 		for _, f := range []string{"MacAddress", "NetworkDisabled", "ExposedPorts"} {
149
-			if _, ok := cfg[f]; !ok {
150
-				c.Fatalf("Api version %s expected to include %s in 'Config'", version, f)
151
-			}
145
+			_, ok := cfg[f]
146
+			c.Check(ok, checker.True, check.Commentf("Api version %s expected to include %s in 'Config'", version, f))
152 147
 		}
153 148
 	}
154 149
 }