Do not omit empty json field in /containers/json api response
Signed-off-by: Antonio Murdaca <runcom@linux.com>
This commit is contained in:
parent
0636bb7b73
commit
725f34151c
|
@ -101,16 +101,16 @@ type Port struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Container struct {
|
type Container struct {
|
||||||
ID string `json:"Id"`
|
ID string `json:"Id"`
|
||||||
Names []string `json:",omitempty"`
|
Names []string
|
||||||
Image string `json:",omitempty"`
|
Image string
|
||||||
Command string `json:",omitempty"`
|
Command string
|
||||||
Created int `json:",omitempty"`
|
Created int
|
||||||
Ports []Port `json:",omitempty"`
|
Ports []Port
|
||||||
SizeRw int `json:",omitempty"`
|
SizeRw int
|
||||||
SizeRootFs int `json:",omitempty"`
|
SizeRootFs int
|
||||||
Labels map[string]string `json:",omitempty"`
|
Labels map[string]string
|
||||||
Status string `json:",omitempty"`
|
Status string
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST "/containers/"+containerID+"/copy"
|
// POST "/containers/"+containerID+"/copy"
|
||||||
|
|
|
@ -51,6 +51,41 @@ func (s *DockerSuite) TestContainerApiGetAll(c *check.C) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// regression test for empty json field being omitted #13691
|
||||||
|
func (s *DockerSuite) TestContainerApiGetJSONNoFieldsOmitted(c *check.C) {
|
||||||
|
runCmd := exec.Command(dockerBinary, "run", "busybox", "true")
|
||||||
|
_, err := runCommand(runCmd)
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
|
status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
|
||||||
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
|
// empty Labels field triggered this bug, make sense to check for everything
|
||||||
|
// cause even Ports for instance can trigger this bug
|
||||||
|
// better safe than sorry..
|
||||||
|
fields := []string{
|
||||||
|
"Id",
|
||||||
|
"Names",
|
||||||
|
"Image",
|
||||||
|
"Command",
|
||||||
|
"Created",
|
||||||
|
"Ports",
|
||||||
|
"SizeRw",
|
||||||
|
"SizeRootFs",
|
||||||
|
"Labels",
|
||||||
|
"Status",
|
||||||
|
}
|
||||||
|
|
||||||
|
// decoding into types.Container do not work since it eventually unmarshal
|
||||||
|
// and empty field to an empty go map, so we just check for a string
|
||||||
|
for _, f := range fields {
|
||||||
|
if !strings.Contains(string(body), f) {
|
||||||
|
c.Fatalf("Field %s is missing and it shouldn't", f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestContainerApiGetExport(c *check.C) {
|
func (s *DockerSuite) TestContainerApiGetExport(c *check.C) {
|
||||||
name := "exportcontainer"
|
name := "exportcontainer"
|
||||||
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test")
|
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test")
|
||||||
|
|
Loading…
Reference in New Issue