1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Remove testutil.ConvertSliceOfStringsToMap

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2017-08-21 18:31:51 -04:00
parent a0c9089971
commit d30e51495a
3 changed files with 16 additions and 35 deletions

View file

@ -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) {

View file

@ -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 {

View file

@ -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 {