mirror of
https://github.com/moby/moby.git
synced 2025-10-24 09:13:09 +03:00
Add network --format flag to ls
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -279,6 +280,43 @@ func (s *DockerNetworkSuite) TestDockerNetworkLsDefault(c *check.C) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestNetworkLsFormat(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "network", "ls", "--format", "{{.Name}}")
|
||||
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
||||
|
||||
expected := []string{"bridge", "host", "none"}
|
||||
var names []string
|
||||
for _, l := range lines {
|
||||
names = append(names, l)
|
||||
}
|
||||
c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestNetworkLsFormatDefaultFormat(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
config := `{
|
||||
"networksFormat": "{{ .Name }} default"
|
||||
}`
|
||||
d, err := ioutil.TempDir("", "integration-cli-")
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer os.RemoveAll(d)
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(d, "config.json"), []byte(config), 0644)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
out, _ := dockerCmd(c, "--config", d, "network", "ls")
|
||||
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
||||
|
||||
expected := []string{"bridge default", "host default", "none default"}
|
||||
var names []string
|
||||
for _, l := range lines {
|
||||
names = append(names, l)
|
||||
}
|
||||
c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names))
|
||||
}
|
||||
|
||||
func (s *DockerNetworkSuite) TestDockerNetworkCreatePredefined(c *check.C) {
|
||||
predefined := []string{"bridge", "host", "none", "default"}
|
||||
for _, net := range predefined {
|
||||
|
||||
Reference in New Issue
Block a user