2015-05-20 08:20:19 -04:00
|
|
|
// +build experimental
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
2015-06-15 01:31:09 -04:00
|
|
|
func assertNwIsAvailable(c *check.C, name string) {
|
|
|
|
if !isNwPresent(c, name) {
|
|
|
|
c.Fatalf("Network %s not found in network ls o/p", name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertNwNotAvailable(c *check.C, name string) {
|
|
|
|
if isNwPresent(c, name) {
|
|
|
|
c.Fatalf("Found network %s in network ls o/p", name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func isNwPresent(c *check.C, name string) bool {
|
2015-05-20 08:20:19 -04:00
|
|
|
runCmd := exec.Command(dockerBinary, "network", "ls")
|
|
|
|
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
2015-06-15 01:31:09 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
2015-05-20 08:20:19 -04:00
|
|
|
lines := strings.Split(out, "\n")
|
|
|
|
for i := 1; i < len(lines)-1; i++ {
|
|
|
|
if strings.Contains(lines[i], name) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestDockerNetworkLsDefault(c *check.C) {
|
|
|
|
defaults := []string{"bridge", "host", "none"}
|
|
|
|
for _, nn := range defaults {
|
2015-06-15 01:31:09 -04:00
|
|
|
assertNwIsAvailable(c, nn)
|
2015-05-20 08:20:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestDockerNetworkCreateDelete(c *check.C) {
|
|
|
|
runCmd := exec.Command(dockerBinary, "network", "create", "test")
|
2015-06-15 01:31:09 -04:00
|
|
|
_, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
assertNwIsAvailable(c, "test")
|
2015-05-20 08:20:19 -04:00
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "network", "rm", "test")
|
2015-06-15 01:31:09 -04:00
|
|
|
_, _, _, err = runCommandWithStdoutStderr(runCmd)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
assertNwNotAvailable(c, "test")
|
2015-05-20 08:20:19 -04:00
|
|
|
}
|