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:
parent
a0c9089971
commit
d30e51495a
3 changed files with 16 additions and 35 deletions
|
@ -4,10 +4,10 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/integration-cli/checker"
|
"github.com/docker/docker/integration-cli/checker"
|
||||||
"github.com/docker/docker/pkg/testutil"
|
|
||||||
"github.com/docker/docker/runconfig"
|
"github.com/docker/docker/runconfig"
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
)
|
)
|
||||||
|
@ -90,40 +90,41 @@ func (s *DockerSuite) TestLinksPingLinkedContainersAfterRename(c *check.C) {
|
||||||
|
|
||||||
func (s *DockerSuite) TestLinksInspectLinksStarted(c *check.C) {
|
func (s *DockerSuite) TestLinksInspectLinksStarted(c *check.C) {
|
||||||
testRequires(c, DaemonIsLinux)
|
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", "container1", "busybox", "top")
|
||||||
dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
|
dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
|
||||||
dockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "top")
|
dockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "top")
|
||||||
links := inspectFieldJSON(c, "testinspectlink", "HostConfig.Links")
|
links := inspectFieldJSON(c, "testinspectlink", "HostConfig.Links")
|
||||||
|
|
||||||
|
var result []string
|
||||||
err := json.Unmarshal([]byte(links), &result)
|
err := json.Unmarshal([]byte(links), &result)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
output := testutil.ConvertSliceOfStringsToMap(result)
|
var expected = []string{
|
||||||
|
"/container1:/testinspectlink/alias1",
|
||||||
c.Assert(output, checker.DeepEquals, expected)
|
"/container2:/testinspectlink/alias2",
|
||||||
|
}
|
||||||
|
sort.Strings(result)
|
||||||
|
c.Assert(result, checker.DeepEquals, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestLinksInspectLinksStopped(c *check.C) {
|
func (s *DockerSuite) TestLinksInspectLinksStopped(c *check.C) {
|
||||||
testRequires(c, DaemonIsLinux)
|
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", "container1", "busybox", "top")
|
||||||
dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
|
dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
|
||||||
dockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "true")
|
dockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "true")
|
||||||
links := inspectFieldJSON(c, "testinspectlink", "HostConfig.Links")
|
links := inspectFieldJSON(c, "testinspectlink", "HostConfig.Links")
|
||||||
|
|
||||||
|
var result []string
|
||||||
err := json.Unmarshal([]byte(links), &result)
|
err := json.Unmarshal([]byte(links), &result)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
output := testutil.ConvertSliceOfStringsToMap(result)
|
var expected = []string{
|
||||||
|
"/container1:/testinspectlink/alias1",
|
||||||
c.Assert(output, checker.DeepEquals, expected)
|
"/container2:/testinspectlink/alias2",
|
||||||
|
}
|
||||||
|
sort.Strings(result)
|
||||||
|
c.Assert(result, checker.DeepEquals, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestLinksNotStartedParentNotFail(c *check.C) {
|
func (s *DockerSuite) TestLinksNotStartedParentNotFail(c *check.C) {
|
||||||
|
|
|
@ -85,16 +85,6 @@ func RunCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode in
|
||||||
return runCommandWithOutput(cmds[len(cmds)-1])
|
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)
|
// CompareDirectoryEntries compares two sets of FileInfo (usually taken from a directory)
|
||||||
// and returns an error if different.
|
// and returns an error if different.
|
||||||
func CompareDirectoryEntries(e1 []os.FileInfo, e2 []os.FileInfo) error {
|
func CompareDirectoryEntries(e1 []os.FileInfo, e2 []os.FileInfo) error {
|
||||||
|
|
|
@ -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) {
|
func TestCompareDirectoryEntries(t *testing.T) {
|
||||||
tmpFolder, err := ioutil.TempDir("", "integration-cli-utils-compare-directories")
|
tmpFolder, err := ioutil.TempDir("", "integration-cli-utils-compare-directories")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue