Fix GET /containers/json emtpy response regression

GET /containers/json route used to reply with and empty array `[]` when no
containers where available. Daemon containers list refactor introduced
this bug by declaring an empty slice istead of initializing it as well
and it was now replying with `null`.

Signed-off-by: Antonio Murdaca <runcom@linux.com>
Upstream-commit: 26bd5e3a2da3157f0bcb6654c30b6eccedf7f3f3
Component: engine
This commit is contained in:
Antonio Murdaca
2015-09-18 18:39:14 +02:00
parent 238b3791d0
commit 3afb789aff
2 changed files with 12 additions and 1 deletions

View File

@ -1514,3 +1514,14 @@ func (s *DockerSuite) TestPutContainerArchiveErrSymlinkInVolumeToReadOnlyRootfs(
c.Fatalf("expected ErrContainerRootfsReadonly error, but got %d: %s", statusCode, string(body))
}
}
func (s *DockerSuite) TestContainersApiGetContainersJSONEmpty(c *check.C) {
testRequires(c, DaemonIsLinux)
status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
c.Assert(err, check.IsNil)
c.Assert(status, check.Equals, http.StatusOK)
if string(body) != "[]\n" {
c.Fatalf("Expected empty response to be `[]`, got %q", string(body))
}
}