Browse code

Remove unnecessary json.Unmarshal wrapper.

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2016/08/05 01:17:37
Showing 8 changed files
... ...
@@ -240,7 +240,7 @@ func (s *DockerSuite) TestBuildEnvironmentReplacementEnv(c *check.C) {
240 240
 
241 241
 	envResult := []string{}
242 242
 
243
-	if err = unmarshalJSON([]byte(res), &envResult); err != nil {
243
+	if err = json.Unmarshal([]byte(res), &envResult); err != nil {
244 244
 		c.Fatal(err)
245 245
 	}
246 246
 
... ...
@@ -297,7 +297,7 @@ func (s *DockerSuite) TestBuildHandleEscapes(c *check.C) {
297 297
 
298 298
 	res := inspectFieldJSON(c, name, "Config.Volumes")
299 299
 
300
-	if err = unmarshalJSON([]byte(res), &result); err != nil {
300
+	if err = json.Unmarshal([]byte(res), &result); err != nil {
301 301
 		c.Fatal(err)
302 302
 	}
303 303
 
... ...
@@ -320,7 +320,7 @@ func (s *DockerSuite) TestBuildHandleEscapes(c *check.C) {
320 320
 
321 321
 	res = inspectFieldJSON(c, name, "Config.Volumes")
322 322
 
323
-	if err = unmarshalJSON([]byte(res), &result); err != nil {
323
+	if err = json.Unmarshal([]byte(res), &result); err != nil {
324 324
 		c.Fatal(err)
325 325
 	}
326 326
 
... ...
@@ -347,7 +347,7 @@ func (s *DockerSuite) TestBuildHandleEscapes(c *check.C) {
347 347
 
348 348
 	res = inspectFieldJSON(c, name, "Config.Volumes")
349 349
 
350
-	if err = unmarshalJSON([]byte(res), &result); err != nil {
350
+	if err = json.Unmarshal([]byte(res), &result); err != nil {
351 351
 		c.Fatal(err)
352 352
 	}
353 353
 
... ...
@@ -1704,7 +1704,7 @@ func (s *DockerSuite) TestBuildWithVolumes(c *check.C) {
1704 1704
 	}
1705 1705
 	res := inspectFieldJSON(c, name, "Config.Volumes")
1706 1706
 
1707
-	err = unmarshalJSON([]byte(res), &result)
1707
+	err = json.Unmarshal([]byte(res), &result)
1708 1708
 	if err != nil {
1709 1709
 		c.Fatal(err)
1710 1710
 	}
... ...
@@ -1833,9 +1833,9 @@ func (s *DockerSuite) TestBuildWindowsAddCopyPathProcessing(c *check.C) {
1833 1833
 			ADD wc2 c:/wc2
1834 1834
 			WORKDIR c:/
1835 1835
 			RUN sh -c "[ $(cat c:/wc1) = 'hellowc1' ]"
1836
-			RUN sh -c "[ $(cat c:/wc2) = 'worldwc2' ]"			
1836
+			RUN sh -c "[ $(cat c:/wc2) = 'worldwc2' ]"
1837 1837
 
1838
-			# Trailing slash on COPY/ADD, Windows-style path. 
1838
+			# Trailing slash on COPY/ADD, Windows-style path.
1839 1839
 			WORKDIR /wd1
1840 1840
 			COPY wd1 c:/wd1/
1841 1841
 			WORKDIR /wd2
... ...
@@ -227,7 +227,7 @@ func (s *DockerSuite) TestInspectBindMountPoint(c *check.C) {
227 227
 	vol := inspectFieldJSON(c, "test", "Mounts")
228 228
 
229 229
 	var mp []types.MountPoint
230
-	err := unmarshalJSON([]byte(vol), &mp)
230
+	err := json.Unmarshal([]byte(vol), &mp)
231 231
 	c.Assert(err, checker.IsNil)
232 232
 
233 233
 	// check that there is only one mountpoint
... ...
@@ -253,7 +253,7 @@ func (s *DockerSuite) TestInspectNamedMountPoint(c *check.C) {
253 253
 	vol := inspectFieldJSON(c, "test", "Mounts")
254 254
 
255 255
 	var mp []types.MountPoint
256
-	err := unmarshalJSON([]byte(vol), &mp)
256
+	err := json.Unmarshal([]byte(vol), &mp)
257 257
 	c.Assert(err, checker.IsNil)
258 258
 
259 259
 	// check that there is only one mountpoint
... ...
@@ -1,6 +1,7 @@
1 1
 package main
2 2
 
3 3
 import (
4
+	"encoding/json"
4 5
 	"fmt"
5 6
 	"regexp"
6 7
 	"strings"
... ...
@@ -97,7 +98,7 @@ func (s *DockerSuite) TestLinksInspectLinksStarted(c *check.C) {
97 97
 	dockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "top")
98 98
 	links := inspectFieldJSON(c, "testinspectlink", "HostConfig.Links")
99 99
 
100
-	err := unmarshalJSON([]byte(links), &result)
100
+	err := json.Unmarshal([]byte(links), &result)
101 101
 	c.Assert(err, checker.IsNil)
102 102
 
103 103
 	output := convertSliceOfStringsToMap(result)
... ...
@@ -116,7 +117,7 @@ func (s *DockerSuite) TestLinksInspectLinksStopped(c *check.C) {
116 116
 	dockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "true")
117 117
 	links := inspectFieldJSON(c, "testinspectlink", "HostConfig.Links")
118 118
 
119
-	err := unmarshalJSON([]byte(links), &result)
119
+	err := json.Unmarshal([]byte(links), &result)
120 120
 	c.Assert(err, checker.IsNil)
121 121
 
122 122
 	output := convertSliceOfStringsToMap(result)
... ...
@@ -3,6 +3,7 @@ package main
3 3
 import (
4 4
 	"bufio"
5 5
 	"bytes"
6
+	"encoding/json"
6 7
 	"fmt"
7 8
 	"io/ioutil"
8 9
 	"net"
... ...
@@ -2397,7 +2398,7 @@ func (s *DockerSuite) TestRunAllowPortRangeThroughExpose(c *check.C) {
2397 2397
 	id := strings.TrimSpace(out)
2398 2398
 	portstr := inspectFieldJSON(c, id, "NetworkSettings.Ports")
2399 2399
 	var ports nat.PortMap
2400
-	if err := unmarshalJSON([]byte(portstr), &ports); err != nil {
2400
+	if err := json.Unmarshal([]byte(portstr), &ports); err != nil {
2401 2401
 		c.Fatal(err)
2402 2402
 	}
2403 2403
 	for port, binding := range ports {
... ...
@@ -2827,7 +2828,7 @@ func (s *DockerSuite) TestRunAllowPortRangeThroughPublish(c *check.C) {
2827 2827
 	portstr := inspectFieldJSON(c, id, "NetworkSettings.Ports")
2828 2828
 
2829 2829
 	var ports nat.PortMap
2830
-	err := unmarshalJSON([]byte(portstr), &ports)
2830
+	err := json.Unmarshal([]byte(portstr), &ports)
2831 2831
 	c.Assert(err, checker.IsNil, check.Commentf("failed to unmarshal: %v", portstr))
2832 2832
 	for port, binding := range ports {
2833 2833
 		portnum, _ := strconv.Atoi(strings.Split(string(port), "/")[0])
... ...
@@ -867,7 +867,7 @@ var errMountNotFound = errors.New("mount point not found")
867 867
 
868 868
 func inspectMountPointJSON(j, destination string) (types.MountPoint, error) {
869 869
 	var mp []types.MountPoint
870
-	if err := unmarshalJSON([]byte(j), &mp); err != nil {
870
+	if err := json.Unmarshal([]byte(j), &mp); err != nil {
871 871
 		return types.MountPoint{}, err
872 872
 	}
873 873
 
... ...
@@ -52,10 +52,6 @@ func runCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode in
52 52
 	return integration.RunCommandPipelineWithOutput(cmds...)
53 53
 }
54 54
 
55
-func unmarshalJSON(data []byte, result interface{}) error {
56
-	return integration.UnmarshalJSON(data, result)
57
-}
58
-
59 55
 func convertSliceOfStringsToMap(input []string) map[string]struct{} {
60 56
 	return integration.ConvertSliceOfStringsToMap(input)
61 57
 }
... ...
@@ -3,7 +3,6 @@ package integration
3 3
 import (
4 4
 	"archive/tar"
5 5
 	"bytes"
6
-	"encoding/json"
7 6
 	"errors"
8 7
 	"fmt"
9 8
 	"io"
... ...
@@ -209,15 +208,6 @@ func RunCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode in
209 209
 	return RunCommandWithOutput(cmds[len(cmds)-1])
210 210
 }
211 211
 
212
-// UnmarshalJSON deserialize a JSON in the given interface.
213
-func UnmarshalJSON(data []byte, result interface{}) error {
214
-	if err := json.Unmarshal(data, result); err != nil {
215
-		return err
216
-	}
217
-
218
-	return nil
219
-}
220
-
221 212
 // ConvertSliceOfStringsToMap converts a slices of string in a map
222 213
 // with the strings as key and an empty string as values.
223 214
 func ConvertSliceOfStringsToMap(input []string) map[string]struct{} {
... ...
@@ -294,21 +294,6 @@ func TestRunCommandPipelineWithOutput(t *testing.T) {
294 294
 	}
295 295
 }
296 296
 
297
-// Simple simple test as it is just a passthrough for json.Unmarshal
298
-func TestUnmarshalJSON(t *testing.T) {
299
-	emptyResult := struct{}{}
300
-	if err := UnmarshalJSON([]byte(""), &emptyResult); err == nil {
301
-		t.Fatalf("Expected an error, got nothing")
302
-	}
303
-	result := struct{ Name string }{}
304
-	if err := UnmarshalJSON([]byte(`{"name": "name"}`), &result); err != nil {
305
-		t.Fatal(err)
306
-	}
307
-	if result.Name != "name" {
308
-		t.Fatalf("Expected result.name to be 'name', was '%s'", result.Name)
309
-	}
310
-}
311
-
312 297
 func TestConvertSliceOfStringsToMap(t *testing.T) {
313 298
 	input := []string{"a", "b"}
314 299
 	actual := ConvertSliceOfStringsToMap(input)