Merge pull request #24528 from rsippl/24526-empty-services-list

Return an empty services list if no services are running
This commit is contained in:
Arnaud Porterie 2016-07-12 18:31:28 +00:00 коммит произвёл GitHub
Родитель a44f010702 65e72133a1
Коммит 79432b4367
3 изменённых файлов: 20 добавлений и 1 удалений

Просмотреть файл

@ -654,7 +654,7 @@ func (c *Cluster) GetServices(options apitypes.ServiceListOptions) ([]types.Serv
return nil, err
}
var services []types.Service
services := []types.Service{}
for _, service := range r.Services {
services = append(services, convert.ServiceFromGRPC(*service))

Просмотреть файл

@ -212,6 +212,16 @@ func (d *SwarmDaemon) listNodes(c *check.C) []swarm.Node {
return nodes
}
func (d *SwarmDaemon) listServices(c *check.C) []swarm.Service {
status, out, err := d.SockRequest("GET", "/services", nil)
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
services := []swarm.Service{}
c.Assert(json.Unmarshal(out, &services), checker.IsNil)
return services
}
func (d *SwarmDaemon) updateSwarm(c *check.C, f ...specConstructor) {
var sw swarm.Swarm
status, out, err := d.SockRequest("GET", "/swarm", nil)

Просмотреть файл

@ -294,6 +294,15 @@ func (s *DockerSwarmSuite) TestApiSwarmPromoteDemote(c *check.C) {
waitAndAssert(c, defaultReconciliationTimeout, d2.checkControlAvailable, checker.True)
}
func (s *DockerSwarmSuite) TestApiSwarmServicesEmptyList(c *check.C) {
testRequires(c, Network)
d := s.AddDaemon(c, true, true)
services := d.listServices(c)
c.Assert(services, checker.NotNil)
c.Assert(len(services), checker.Equals, 0, check.Commentf("services: %#v", services))
}
func (s *DockerSwarmSuite) TestApiSwarmServicesCreate(c *check.C) {
testRequires(c, Network)
d := s.AddDaemon(c, true, true)