docker_api_service_update_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // +build !windows
  2. package main
  3. import (
  4. "github.com/docker/docker/api/types/swarm"
  5. "github.com/docker/docker/integration-cli/daemon"
  6. "github.com/docker/docker/pkg/integration/checker"
  7. "github.com/go-check/check"
  8. )
  9. func setPortConfig(portConfig []swarm.PortConfig) daemon.ServiceConstructor {
  10. return func(s *swarm.Service) {
  11. if s.Spec.EndpointSpec == nil {
  12. s.Spec.EndpointSpec = &swarm.EndpointSpec{}
  13. }
  14. s.Spec.EndpointSpec.Ports = portConfig
  15. }
  16. }
  17. func (s *DockerSwarmSuite) TestAPIServiceUpdatePort(c *check.C) {
  18. d := s.AddDaemon(c, true, true)
  19. // Create a service with a port mapping of 8080:8081.
  20. portConfig := []swarm.PortConfig{{TargetPort: 8081, PublishedPort: 8080}}
  21. serviceID := d.CreateService(c, simpleTestService, setInstances(1), setPortConfig(portConfig))
  22. waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1)
  23. // Update the service: changed the port mapping from 8080:8081 to 8082:8083.
  24. updatedPortConfig := []swarm.PortConfig{{TargetPort: 8083, PublishedPort: 8082}}
  25. remoteService := d.GetService(c, serviceID)
  26. d.UpdateService(c, remoteService, setPortConfig(updatedPortConfig))
  27. // Inspect the service and verify port mapping.
  28. updatedService := d.GetService(c, serviceID)
  29. c.Assert(updatedService.Spec.EndpointSpec, check.NotNil)
  30. c.Assert(len(updatedService.Spec.EndpointSpec.Ports), check.Equals, 1)
  31. c.Assert(updatedService.Spec.EndpointSpec.Ports[0].TargetPort, check.Equals, uint32(8083))
  32. c.Assert(updatedService.Spec.EndpointSpec.Ports[0].PublishedPort, check.Equals, uint32(8082))
  33. }