mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Remove unnecessary json.Unmarshal wrapper.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
0b2ff0ccde
commit
fb42e84772
8 changed files with 16 additions and 43 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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{} {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue