1
0
mirror of https://github.com/moby/moby.git synced 2025-08-01 05:47:11 +03:00

Assert error in body of function inspectField*

1. Replace raw `docker inspect -f xxx` with `inspectField`, to make code
cleaner and more consistent
2. assert the error in function `inspectField*` so we don't need to
assert the return value of it every time, this will make inspect easier.

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
This commit is contained in:
Zhang Wei
2016-01-28 22:19:25 +08:00
parent 725b5b595b
commit 62a856e912
34 changed files with 298 additions and 591 deletions

View File

@ -288,23 +288,21 @@ func (s *DockerSuite) TestInspectExecID(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
id := strings.TrimSuffix(out, "\n")
out, err := inspectField(id, "ExecIDs")
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect container: %s", out))
out = inspectField(c, id, "ExecIDs")
c.Assert(out, checker.Equals, "[]", check.Commentf("ExecIDs should be empty, got: %s", out))
// Start an exec, have it block waiting so we can do some checking
cmd := exec.Command(dockerBinary, "exec", id, "sh", "-c",
"while ! test -e /tmp/execid1; do sleep 1; done")
err = cmd.Start()
err := cmd.Start()
c.Assert(err, checker.IsNil, check.Commentf("failed to start the exec cmd"))
// Give the exec 10 chances/seconds to start then give up and stop the test
tries := 10
for i := 0; i < tries; i++ {
// Since its still running we should see exec as part of the container
out, err = inspectField(id, "ExecIDs")
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect container: %s", out))
out = inspectField(c, id, "ExecIDs")
out = strings.TrimSuffix(out, "\n")
if out != "[]" && out != "<no value>" {
@ -328,8 +326,7 @@ func (s *DockerSuite) TestInspectExecID(c *check.C) {
cmd.Wait()
// All execs for the container should be gone now
out, err = inspectField(id, "ExecIDs")
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect container: %s", out))
out = inspectField(c, id, "ExecIDs")
out = strings.TrimSuffix(out, "\n")
c.Assert(out == "[]" || out == "<no value>", checker.True)