From d30e51495a7b748d0d5e73e1b8c7edf5c584c4ef Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Mon, 21 Aug 2017 18:31:51 -0400 Subject: [PATCH] Remove testutil.ConvertSliceOfStringsToMap Signed-off-by: Daniel Nephin --- integration-cli/docker_cli_links_test.go | 31 ++++++++++++------------ pkg/testutil/utils.go | 10 -------- pkg/testutil/utils_test.go | 10 -------- 3 files changed, 16 insertions(+), 35 deletions(-) diff --git a/integration-cli/docker_cli_links_test.go b/integration-cli/docker_cli_links_test.go index 7c9ce739ce..0b4f30cfe9 100644 --- a/integration-cli/docker_cli_links_test.go +++ b/integration-cli/docker_cli_links_test.go @@ -4,10 +4,10 @@ import ( "encoding/json" "fmt" "regexp" + "sort" "strings" "github.com/docker/docker/integration-cli/checker" - "github.com/docker/docker/pkg/testutil" "github.com/docker/docker/runconfig" "github.com/go-check/check" ) @@ -90,40 +90,41 @@ func (s *DockerSuite) TestLinksPingLinkedContainersAfterRename(c *check.C) { func (s *DockerSuite) TestLinksInspectLinksStarted(c *check.C) { testRequires(c, DaemonIsLinux) - var ( - expected = map[string]struct{}{"/container1:/testinspectlink/alias1": {}, "/container2:/testinspectlink/alias2": {}} - result []string - ) dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top") dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top") dockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "top") links := inspectFieldJSON(c, "testinspectlink", "HostConfig.Links") + var result []string err := json.Unmarshal([]byte(links), &result) c.Assert(err, checker.IsNil) - output := testutil.ConvertSliceOfStringsToMap(result) - - c.Assert(output, checker.DeepEquals, expected) + var expected = []string{ + "/container1:/testinspectlink/alias1", + "/container2:/testinspectlink/alias2", + } + sort.Strings(result) + c.Assert(result, checker.DeepEquals, expected) } func (s *DockerSuite) TestLinksInspectLinksStopped(c *check.C) { testRequires(c, DaemonIsLinux) - var ( - expected = map[string]struct{}{"/container1:/testinspectlink/alias1": {}, "/container2:/testinspectlink/alias2": {}} - result []string - ) + dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top") dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top") dockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "true") links := inspectFieldJSON(c, "testinspectlink", "HostConfig.Links") + var result []string err := json.Unmarshal([]byte(links), &result) c.Assert(err, checker.IsNil) - output := testutil.ConvertSliceOfStringsToMap(result) - - c.Assert(output, checker.DeepEquals, expected) + var expected = []string{ + "/container1:/testinspectlink/alias1", + "/container2:/testinspectlink/alias2", + } + sort.Strings(result) + c.Assert(result, checker.DeepEquals, expected) } func (s *DockerSuite) TestLinksNotStartedParentNotFail(c *check.C) { diff --git a/pkg/testutil/utils.go b/pkg/testutil/utils.go index 0522dde2b1..a4e5f1f37f 100644 --- a/pkg/testutil/utils.go +++ b/pkg/testutil/utils.go @@ -85,16 +85,6 @@ func RunCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode in return runCommandWithOutput(cmds[len(cmds)-1]) } -// 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{} { - output := make(map[string]struct{}) - for _, v := range input { - output[v] = struct{}{} - } - return output -} - // CompareDirectoryEntries compares two sets of FileInfo (usually taken from a directory) // and returns an error if different. func CompareDirectoryEntries(e1 []os.FileInfo, e2 []os.FileInfo) error { diff --git a/pkg/testutil/utils_test.go b/pkg/testutil/utils_test.go index d37f3f4f83..0ddf691c18 100644 --- a/pkg/testutil/utils_test.go +++ b/pkg/testutil/utils_test.go @@ -100,16 +100,6 @@ func TestRunCommandPipelineWithOutput(t *testing.T) { } } -func TestConvertSliceOfStringsToMap(t *testing.T) { - input := []string{"a", "b"} - actual := ConvertSliceOfStringsToMap(input) - for _, key := range input { - if _, ok := actual[key]; !ok { - t.Fatalf("Expected output to contains key %s, did not: %v", key, actual) - } - } -} - func TestCompareDirectoryEntries(t *testing.T) { tmpFolder, err := ioutil.TempDir("", "integration-cli-utils-compare-directories") if err != nil {