From fb42e8477208badf0714a9d8ae20946a9b531dba Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Thu, 4 Aug 2016 12:17:37 -0400 Subject: [PATCH] Remove unnecessary json.Unmarshal wrapper. Signed-off-by: Daniel Nephin --- integration-cli/docker_cli_build_test.go | 14 +++++++------- integration-cli/docker_cli_inspect_test.go | 4 ++-- integration-cli/docker_cli_links_test.go | 5 +++-- integration-cli/docker_cli_run_test.go | 5 +++-- integration-cli/docker_utils.go | 2 +- integration-cli/utils.go | 4 ---- pkg/integration/utils.go | 10 ---------- pkg/integration/utils_test.go | 15 --------------- 8 files changed, 16 insertions(+), 43 deletions(-) diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 32497d1e56..5201f731af 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -240,7 +240,7 @@ func (s *DockerSuite) TestBuildEnvironmentReplacementEnv(c *check.C) { envResult := []string{} - if err = unmarshalJSON([]byte(res), &envResult); err != nil { + if err = json.Unmarshal([]byte(res), &envResult); err != nil { c.Fatal(err) } @@ -297,7 +297,7 @@ func (s *DockerSuite) TestBuildHandleEscapes(c *check.C) { res := inspectFieldJSON(c, name, "Config.Volumes") - if err = unmarshalJSON([]byte(res), &result); err != nil { + if err = json.Unmarshal([]byte(res), &result); err != nil { c.Fatal(err) } @@ -320,7 +320,7 @@ func (s *DockerSuite) TestBuildHandleEscapes(c *check.C) { res = inspectFieldJSON(c, name, "Config.Volumes") - if err = unmarshalJSON([]byte(res), &result); err != nil { + if err = json.Unmarshal([]byte(res), &result); err != nil { c.Fatal(err) } @@ -347,7 +347,7 @@ func (s *DockerSuite) TestBuildHandleEscapes(c *check.C) { res = inspectFieldJSON(c, name, "Config.Volumes") - if err = unmarshalJSON([]byte(res), &result); err != nil { + if err = json.Unmarshal([]byte(res), &result); err != nil { c.Fatal(err) } @@ -1704,7 +1704,7 @@ func (s *DockerSuite) TestBuildWithVolumes(c *check.C) { } res := inspectFieldJSON(c, name, "Config.Volumes") - err = unmarshalJSON([]byte(res), &result) + err = json.Unmarshal([]byte(res), &result) if err != nil { c.Fatal(err) } @@ -1833,9 +1833,9 @@ func (s *DockerSuite) TestBuildWindowsAddCopyPathProcessing(c *check.C) { ADD wc2 c:/wc2 WORKDIR c:/ RUN sh -c "[ $(cat c:/wc1) = 'hellowc1' ]" - RUN sh -c "[ $(cat c:/wc2) = 'worldwc2' ]" + RUN sh -c "[ $(cat c:/wc2) = 'worldwc2' ]" - # Trailing slash on COPY/ADD, Windows-style path. + # Trailing slash on COPY/ADD, Windows-style path. WORKDIR /wd1 COPY wd1 c:/wd1/ WORKDIR /wd2 diff --git a/integration-cli/docker_cli_inspect_test.go b/integration-cli/docker_cli_inspect_test.go index 1bab86f419..6c61984d80 100644 --- a/integration-cli/docker_cli_inspect_test.go +++ b/integration-cli/docker_cli_inspect_test.go @@ -227,7 +227,7 @@ func (s *DockerSuite) TestInspectBindMountPoint(c *check.C) { vol := inspectFieldJSON(c, "test", "Mounts") var mp []types.MountPoint - err := unmarshalJSON([]byte(vol), &mp) + err := json.Unmarshal([]byte(vol), &mp) c.Assert(err, checker.IsNil) // check that there is only one mountpoint @@ -253,7 +253,7 @@ func (s *DockerSuite) TestInspectNamedMountPoint(c *check.C) { vol := inspectFieldJSON(c, "test", "Mounts") var mp []types.MountPoint - err := unmarshalJSON([]byte(vol), &mp) + err := json.Unmarshal([]byte(vol), &mp) c.Assert(err, checker.IsNil) // check that there is only one mountpoint diff --git a/integration-cli/docker_cli_links_test.go b/integration-cli/docker_cli_links_test.go index d4bfc6a128..a5872d9e0c 100644 --- a/integration-cli/docker_cli_links_test.go +++ b/integration-cli/docker_cli_links_test.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "fmt" "regexp" "strings" @@ -97,7 +98,7 @@ func (s *DockerSuite) TestLinksInspectLinksStarted(c *check.C) { dockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "top") links := inspectFieldJSON(c, "testinspectlink", "HostConfig.Links") - err := unmarshalJSON([]byte(links), &result) + err := json.Unmarshal([]byte(links), &result) c.Assert(err, checker.IsNil) output := convertSliceOfStringsToMap(result) @@ -116,7 +117,7 @@ func (s *DockerSuite) TestLinksInspectLinksStopped(c *check.C) { dockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "true") links := inspectFieldJSON(c, "testinspectlink", "HostConfig.Links") - err := unmarshalJSON([]byte(links), &result) + err := json.Unmarshal([]byte(links), &result) c.Assert(err, checker.IsNil) output := convertSliceOfStringsToMap(result) diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index e0820d572c..965bdb9644 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -3,6 +3,7 @@ package main import ( "bufio" "bytes" + "encoding/json" "fmt" "io/ioutil" "net" @@ -2397,7 +2398,7 @@ func (s *DockerSuite) TestRunAllowPortRangeThroughExpose(c *check.C) { id := strings.TrimSpace(out) portstr := inspectFieldJSON(c, id, "NetworkSettings.Ports") var ports nat.PortMap - if err := unmarshalJSON([]byte(portstr), &ports); err != nil { + if err := json.Unmarshal([]byte(portstr), &ports); err != nil { c.Fatal(err) } for port, binding := range ports { @@ -2827,7 +2828,7 @@ func (s *DockerSuite) TestRunAllowPortRangeThroughPublish(c *check.C) { portstr := inspectFieldJSON(c, id, "NetworkSettings.Ports") var ports nat.PortMap - err := unmarshalJSON([]byte(portstr), &ports) + err := json.Unmarshal([]byte(portstr), &ports) c.Assert(err, checker.IsNil, check.Commentf("failed to unmarshal: %v", portstr)) for port, binding := range ports { portnum, _ := strconv.Atoi(strings.Split(string(port), "/")[0]) diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go index 1141cae2c1..238929c16c 100644 --- a/integration-cli/docker_utils.go +++ b/integration-cli/docker_utils.go @@ -867,7 +867,7 @@ var errMountNotFound = errors.New("mount point not found") func inspectMountPointJSON(j, destination string) (types.MountPoint, error) { var mp []types.MountPoint - if err := unmarshalJSON([]byte(j), &mp); err != nil { + if err := json.Unmarshal([]byte(j), &mp); err != nil { return types.MountPoint{}, err } diff --git a/integration-cli/utils.go b/integration-cli/utils.go index 149f1c4540..eac6379bcd 100644 --- a/integration-cli/utils.go +++ b/integration-cli/utils.go @@ -52,10 +52,6 @@ func runCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode in return integration.RunCommandPipelineWithOutput(cmds...) } -func unmarshalJSON(data []byte, result interface{}) error { - return integration.UnmarshalJSON(data, result) -} - func convertSliceOfStringsToMap(input []string) map[string]struct{} { return integration.ConvertSliceOfStringsToMap(input) } diff --git a/pkg/integration/utils.go b/pkg/integration/utils.go index cfccc80143..a8293f64cf 100644 --- a/pkg/integration/utils.go +++ b/pkg/integration/utils.go @@ -3,7 +3,6 @@ package integration import ( "archive/tar" "bytes" - "encoding/json" "errors" "fmt" "io" @@ -209,15 +208,6 @@ func RunCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode in return RunCommandWithOutput(cmds[len(cmds)-1]) } -// UnmarshalJSON deserialize a JSON in the given interface. -func UnmarshalJSON(data []byte, result interface{}) error { - if err := json.Unmarshal(data, result); err != nil { - return err - } - - return nil -} - // ConvertSliceOfStringsToMap converts a slices of string in a map // with the strings as key and an empty string as values. func ConvertSliceOfStringsToMap(input []string) map[string]struct{} { diff --git a/pkg/integration/utils_test.go b/pkg/integration/utils_test.go index b354ab932d..26d0e3d0c3 100644 --- a/pkg/integration/utils_test.go +++ b/pkg/integration/utils_test.go @@ -294,21 +294,6 @@ func TestRunCommandPipelineWithOutput(t *testing.T) { } } -// Simple simple test as it is just a passthrough for json.Unmarshal -func TestUnmarshalJSON(t *testing.T) { - emptyResult := struct{}{} - if err := UnmarshalJSON([]byte(""), &emptyResult); err == nil { - t.Fatalf("Expected an error, got nothing") - } - result := struct{ Name string }{} - if err := UnmarshalJSON([]byte(`{"name": "name"}`), &result); err != nil { - t.Fatal(err) - } - if result.Name != "name" { - t.Fatalf("Expected result.name to be 'name', was '%s'", result.Name) - } -} - func TestConvertSliceOfStringsToMap(t *testing.T) { input := []string{"a", "b"} actual := ConvertSliceOfStringsToMap(input)