mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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
2 changed files with 45 additions and 10 deletions
|
@ -101,16 +101,16 @@ type Port struct {
|
|||
}
|
||||
|
||||
type Container struct {
|
||||
ID string `json:"Id"`
|
||||
Names []string `json:",omitempty"`
|
||||
Image string `json:",omitempty"`
|
||||
Command string `json:",omitempty"`
|
||||
Created int `json:",omitempty"`
|
||||
Ports []Port `json:",omitempty"`
|
||||
SizeRw int `json:",omitempty"`
|
||||
SizeRootFs int `json:",omitempty"`
|
||||
Labels map[string]string `json:",omitempty"`
|
||||
Status string `json:",omitempty"`
|
||||
ID string `json:"Id"`
|
||||
Names []string
|
||||
Image string
|
||||
Command string
|
||||
Created int
|
||||
Ports []Port
|
||||
SizeRw int
|
||||
SizeRootFs int
|
||||
Labels map[string]string
|
||||
Status string
|
||||
}
|
||||
|
||||
// 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) {
|
||||
name := "exportcontainer"
|
||||
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test")
|
||||
|
|
Loading…
Reference in a new issue