Signed-off-by: Wen Cheng Ma <wenchma@cn.ibm.com>
Wen Cheng Ma authored on 2015/12/28 17:29:39... | ... |
@@ -20,8 +20,9 @@ parent = "smn_cli" |
20 | 20 |
values are "image" or "container" |
21 | 21 |
-s, --size Display total file sizes if the type is container |
22 | 22 |
|
23 |
-By default, this will render all results in a JSON array. If a format is |
|
24 |
-specified, the given template will be executed for each result. |
|
23 |
+By default, this will render all results in a JSON array. If the container and |
|
24 |
+image have the same name, this will return container JSON for unspecified type. |
|
25 |
+If a format is specified, the given template will be executed for each result. |
|
25 | 26 |
|
26 | 27 |
Go's [text/template](http://golang.org/pkg/text/template/) package |
27 | 28 |
describes all the details of the format. |
... | ... |
@@ -49,8 +49,12 @@ func (s *DockerSuite) TestInspectDefault(c *check.C) { |
49 | 49 |
//Both the container and image are named busybox. docker inspect will fetch the container JSON. |
50 | 50 |
//If the container JSON is not available, it will go for the image JSON. |
51 | 51 |
|
52 |
- dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true") |
|
53 |
- dockerCmd(c, "inspect", "busybox") |
|
52 |
+ out, _ := dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true") |
|
53 |
+ containerID := strings.TrimSpace(out) |
|
54 |
+ |
|
55 |
+ inspectOut, err := inspectField("busybox", "Id") |
|
56 |
+ c.Assert(err, checker.IsNil) |
|
57 |
+ c.Assert(strings.TrimSpace(inspectOut), checker.Equals, containerID) |
|
54 | 58 |
} |
55 | 59 |
|
56 | 60 |
func (s *DockerSuite) TestInspectStatus(c *check.C) { |
... | ... |
@@ -329,13 +333,15 @@ func (s *DockerSuite) TestInspectSizeFlagImage(c *check.C) { |
329 | 329 |
} |
330 | 330 |
|
331 | 331 |
func (s *DockerSuite) TestInspectTempateError(c *check.C) { |
332 |
- //Both the container and image are named busybox. docker inspect will fetch container |
|
333 |
- //JSON State.Running field. If the field is true, it's a container. |
|
332 |
+ // Template parsing error for both the container and image. |
|
334 | 333 |
|
335 |
- dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top") |
|
334 |
+ dockerCmd(c, "run", "--name=container1", "-d", "busybox", "top") |
|
336 | 335 |
|
337 |
- out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='Format container: {{.ThisDoesNotExist}}'", "busybox") |
|
336 |
+ out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='Format container: {{.ThisDoesNotExist}}'", "container1") |
|
337 |
+ c.Assert(err, check.Not(check.IsNil)) |
|
338 |
+ c.Assert(out, checker.Contains, "Template parsing error") |
|
338 | 339 |
|
340 |
+ out, _, err = dockerCmdWithError("inspect", "--type=image", "--format='Format container: {{.ThisDoesNotExist}}'", "busybox") |
|
339 | 341 |
c.Assert(err, check.Not(check.IsNil)) |
340 | 342 |
c.Assert(out, checker.Contains, "Template parsing error") |
341 | 343 |
} |
... | ... |
@@ -16,8 +16,9 @@ CONTAINER|IMAGE [CONTAINER|IMAGE...] |
16 | 16 |
|
17 | 17 |
This displays all the information available in Docker for a given |
18 | 18 |
container or image. By default, this will render all results in a JSON |
19 |
-array. If a format is specified, the given template will be executed for |
|
20 |
-each result. |
|
19 |
+array. If the container and image have the same name, this will return |
|
20 |
+container JSON for unspecified type. If a format is specified, the given |
|
21 |
+template will be executed for each result. |
|
21 | 22 |
|
22 | 23 |
# OPTIONS |
23 | 24 |
**--help** |