Browse code

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>

Antonio Murdaca authored on 2015/09/19 01:39:14
Showing 2 changed files
... ...
@@ -84,7 +84,7 @@ func (daemon *Daemon) Containers(config *ContainersConfig) ([]*types.Container,
84 84
 
85 85
 // reduceContainer parses the user filtering and generates the list of containers to return based on a reducer.
86 86
 func (daemon *Daemon) reduceContainers(config *ContainersConfig, reducer containerReducer) ([]*types.Container, error) {
87
-	var containers []*types.Container
87
+	containers := []*types.Container{}
88 88
 
89 89
 	ctx, err := daemon.foldFilter(config)
90 90
 	if err != nil {
... ...
@@ -1514,3 +1514,14 @@ func (s *DockerSuite) TestPutContainerArchiveErrSymlinkInVolumeToReadOnlyRootfs(
1514 1514
 		c.Fatalf("expected ErrContainerRootfsReadonly error, but got %d: %s", statusCode, string(body))
1515 1515
 	}
1516 1516
 }
1517
+
1518
+func (s *DockerSuite) TestContainersApiGetContainersJSONEmpty(c *check.C) {
1519
+	testRequires(c, DaemonIsLinux)
1520
+
1521
+	status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
1522
+	c.Assert(err, check.IsNil)
1523
+	c.Assert(status, check.Equals, http.StatusOK)
1524
+	if string(body) != "[]\n" {
1525
+		c.Fatalf("Expected empty response to be `[]`, got %q", string(body))
1526
+	}
1527
+}