From 9fbb1306e83576086e924ff4fbf35b9a74beb28a Mon Sep 17 00:00:00 2001 From: Wen Cheng Ma Date: Mon, 28 Dec 2015 16:29:39 +0800 Subject: [PATCH] Update integration tests when container and image have same name Signed-off-by: Wen Cheng Ma --- docs/reference/commandline/inspect.md | 5 +++-- integration-cli/docker_cli_inspect_test.go | 18 ++++++++++++------ man/docker-inspect.1.md | 5 +++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/docs/reference/commandline/inspect.md b/docs/reference/commandline/inspect.md index 434f98989f..995388c8f1 100644 --- a/docs/reference/commandline/inspect.md +++ b/docs/reference/commandline/inspect.md @@ -20,8 +20,9 @@ parent = "smn_cli" values are "image" or "container" -s, --size Display total file sizes if the type is container -By default, this will render all results in a JSON array. If a format is -specified, the given template will be executed for each result. +By default, this will render all results in a JSON array. If the container and +image have the same name, this will return container JSON for unspecified type. +If a format is specified, the given template will be executed for each result. Go's [text/template](http://golang.org/pkg/text/template/) package describes all the details of the format. diff --git a/integration-cli/docker_cli_inspect_test.go b/integration-cli/docker_cli_inspect_test.go index d471936be4..7d1499c1d6 100644 --- a/integration-cli/docker_cli_inspect_test.go +++ b/integration-cli/docker_cli_inspect_test.go @@ -49,8 +49,12 @@ func (s *DockerSuite) TestInspectDefault(c *check.C) { //Both the container and image are named busybox. docker inspect will fetch the container JSON. //If the container JSON is not available, it will go for the image JSON. - dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true") - dockerCmd(c, "inspect", "busybox") + out, _ := dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true") + containerID := strings.TrimSpace(out) + + inspectOut, err := inspectField("busybox", "Id") + c.Assert(err, checker.IsNil) + c.Assert(strings.TrimSpace(inspectOut), checker.Equals, containerID) } func (s *DockerSuite) TestInspectStatus(c *check.C) { @@ -329,13 +333,15 @@ func (s *DockerSuite) TestInspectSizeFlagImage(c *check.C) { } func (s *DockerSuite) TestInspectTempateError(c *check.C) { - //Both the container and image are named busybox. docker inspect will fetch container - //JSON State.Running field. If the field is true, it's a container. + // Template parsing error for both the container and image. - dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top") + dockerCmd(c, "run", "--name=container1", "-d", "busybox", "top") - out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='Format container: {{.ThisDoesNotExist}}'", "busybox") + out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='Format container: {{.ThisDoesNotExist}}'", "container1") + c.Assert(err, check.Not(check.IsNil)) + c.Assert(out, checker.Contains, "Template parsing error") + out, _, err = dockerCmdWithError("inspect", "--type=image", "--format='Format container: {{.ThisDoesNotExist}}'", "busybox") c.Assert(err, check.Not(check.IsNil)) c.Assert(out, checker.Contains, "Template parsing error") } diff --git a/man/docker-inspect.1.md b/man/docker-inspect.1.md index 81f48ceedf..9babd569ac 100644 --- a/man/docker-inspect.1.md +++ b/man/docker-inspect.1.md @@ -16,8 +16,9 @@ CONTAINER|IMAGE [CONTAINER|IMAGE...] This displays all the information available in Docker for a given container or image. By default, this will render all results in a JSON -array. If a format is specified, the given template will be executed for -each result. +array. If the container and image have the same name, this will return +container JSON for unspecified type. If a format is specified, the given +template will be executed for each result. # OPTIONS **--help**