fix inspect format result

Currently `docker inspect -f` use json.Unmarshal() unmarshal
to interface, it will store all JSON numbers in float64, so
we use `docker inspect 4f0d73b75a0d | grep Memory` and
`docker inspect -f {{.HostConfig.Memory}} 4f0d73b75a0d` will
get different values.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Upstream-commit: b0ef3194aaa8c22b674ed5301c59e8e557a7e85e
Component: engine
This commit is contained in:
Qiang Huang
2015-04-23 09:28:07 +08:00
parent 0f579f7454
commit 1c1b244ecd
3 changed files with 34 additions and 11 deletions

View File

@ -21,3 +21,23 @@ func (s *DockerSuite) TestInspectImage(c *check.C) {
}
}
func (s *DockerSuite) TestInspectInt64(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "-m=300M", "busybox", "true")
out, _, _, err := runCommandWithStdoutStderr(runCmd)
if err != nil {
c.Fatalf("failed to run container: %v, output: %q", err, out)
}
out = strings.TrimSpace(out)
inspectCmd := exec.Command(dockerBinary, "inspect", "-f", "{{.HostConfig.Memory}}", out)
inspectOut, _, err := runCommandWithOutput(inspectCmd)
if err != nil {
c.Fatalf("failed to inspect container: %v, output: %q", err, inspectOut)
}
if strings.TrimSpace(inspectOut) != "314572800" {
c.Fatalf("inspect got wrong value, got: %q, expected: 314572800", inspectOut)
}
}