docker_cli_service_update_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // +build !windows
  2. package main
  3. import (
  4. "encoding/json"
  5. "github.com/docker/docker/pkg/integration/checker"
  6. "github.com/docker/engine-api/types/swarm"
  7. "github.com/go-check/check"
  8. )
  9. func (s *DockerSwarmSuite) TestServiceUpdatePort(c *check.C) {
  10. d := s.AddDaemon(c, true, true)
  11. serviceName := "TestServiceUpdatePort"
  12. serviceArgs := append([]string{"create", "--name", serviceName, "-p", "8080:8081", defaultSleepImage}, defaultSleepCommand...)
  13. // Create a service with a port mapping of 8080:8081.
  14. out, err := d.Cmd("service", serviceArgs...)
  15. c.Assert(err, checker.IsNil)
  16. waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1)
  17. // Update the service: changed the port mapping from 8080:8081 to 8082:8083.
  18. _, err = d.Cmd("service", "update", "-p", "8082:8083", serviceName)
  19. c.Assert(err, checker.IsNil)
  20. // Inspect the service and verify port mapping
  21. expected := []swarm.PortConfig{
  22. {
  23. Protocol: "tcp",
  24. PublishedPort: 8082,
  25. TargetPort: 8083,
  26. },
  27. }
  28. out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.EndpointSpec.Ports }}", serviceName)
  29. c.Assert(err, checker.IsNil)
  30. var portConfig []swarm.PortConfig
  31. if err := json.Unmarshal([]byte(out), &portConfig); err != nil {
  32. c.Fatalf("invalid JSON in inspect result: %v (%s)", err, out)
  33. }
  34. c.Assert(portConfig, checker.DeepEquals, expected)
  35. }