1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- // +build experimental
- package main
- import (
- "os/exec"
- "strings"
- "github.com/go-check/check"
- )
- func isSrvAvailable(c *check.C, sname string, name string) bool {
- runCmd := exec.Command(dockerBinary, "service", "ls")
- out, _, _, err := runCommandWithStdoutStderr(runCmd)
- if err != nil {
- c.Fatal(out, err)
- }
- lines := strings.Split(out, "\n")
- for i := 1; i < len(lines)-1; i++ {
- if strings.Contains(lines[i], sname) && strings.Contains(lines[i], name) {
- return true
- }
- }
- return false
- }
- func isNwAvailable(c *check.C, name string) bool {
- runCmd := exec.Command(dockerBinary, "network", "ls")
- out, _, _, err := runCommandWithStdoutStderr(runCmd)
- if err != nil {
- c.Fatal(out, err)
- }
- 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) TestDockerServiceCreateDelete(c *check.C) {
- runCmd := exec.Command(dockerBinary, "network", "create", "test")
- out, _, _, err := runCommandWithStdoutStderr(runCmd)
- if err != nil {
- c.Fatal(out, err)
- }
- if !isNwAvailable(c, "test") {
- c.Fatalf("Network test not found")
- }
- runCmd = exec.Command(dockerBinary, "service", "publish", "s1.test")
- out, _, _, err = runCommandWithStdoutStderr(runCmd)
- if err != nil {
- c.Fatal(out, err)
- }
- if !isSrvAvailable(c, "s1", "test") {
- c.Fatalf("service s1.test not found")
- }
- runCmd = exec.Command(dockerBinary, "service", "unpublish", "s1.test")
- out, _, _, err = runCommandWithStdoutStderr(runCmd)
- if err != nil {
- c.Fatal(out, err)
- }
- if isSrvAvailable(c, "s1", "test") {
- c.Fatalf("service s1.test not removed")
- }
- runCmd = exec.Command(dockerBinary, "network", "rm", "test")
- out, _, _, err = runCommandWithStdoutStderr(runCmd)
- if err != nil {
- c.Fatal(out, err)
- }
- if isNetworkPresent(c, "test") {
- c.Fatalf("Network test is not removed")
- }
- }
|