docker_cli_service_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // +build experimental
  2. package main
  3. import (
  4. "os/exec"
  5. "strings"
  6. "github.com/go-check/check"
  7. )
  8. func isSrvAvailable(c *check.C, sname string, name string) bool {
  9. runCmd := exec.Command(dockerBinary, "service", "ls")
  10. out, _, _, err := runCommandWithStdoutStderr(runCmd)
  11. if err != nil {
  12. c.Fatal(out, err)
  13. }
  14. lines := strings.Split(out, "\n")
  15. for i := 1; i < len(lines)-1; i++ {
  16. if strings.Contains(lines[i], sname) && strings.Contains(lines[i], name) {
  17. return true
  18. }
  19. }
  20. return false
  21. }
  22. func isNwAvailable(c *check.C, name string) bool {
  23. runCmd := exec.Command(dockerBinary, "network", "ls")
  24. out, _, _, err := runCommandWithStdoutStderr(runCmd)
  25. if err != nil {
  26. c.Fatal(out, err)
  27. }
  28. lines := strings.Split(out, "\n")
  29. for i := 1; i < len(lines)-1; i++ {
  30. if strings.Contains(lines[i], name) {
  31. return true
  32. }
  33. }
  34. return false
  35. }
  36. func (s *DockerSuite) TestDockerServiceCreateDelete(c *check.C) {
  37. runCmd := exec.Command(dockerBinary, "network", "create", "test")
  38. out, _, _, err := runCommandWithStdoutStderr(runCmd)
  39. if err != nil {
  40. c.Fatal(out, err)
  41. }
  42. if !isNwAvailable(c, "test") {
  43. c.Fatalf("Network test not found")
  44. }
  45. runCmd = exec.Command(dockerBinary, "service", "publish", "s1.test")
  46. out, _, _, err = runCommandWithStdoutStderr(runCmd)
  47. if err != nil {
  48. c.Fatal(out, err)
  49. }
  50. if !isSrvAvailable(c, "s1", "test") {
  51. c.Fatalf("service s1.test not found")
  52. }
  53. runCmd = exec.Command(dockerBinary, "service", "unpublish", "s1.test")
  54. out, _, _, err = runCommandWithStdoutStderr(runCmd)
  55. if err != nil {
  56. c.Fatal(out, err)
  57. }
  58. if isSrvAvailable(c, "s1", "test") {
  59. c.Fatalf("service s1.test not removed")
  60. }
  61. runCmd = exec.Command(dockerBinary, "network", "rm", "test")
  62. out, _, _, err = runCommandWithStdoutStderr(runCmd)
  63. if err != nil {
  64. c.Fatal(out, err)
  65. }
  66. if isNetworkPresent(c, "test") {
  67. c.Fatalf("Network test is not removed")
  68. }
  69. }