update integration-cli/docker_cli_stats_test.go use Assert statement

part of #16756

Signed-off-by: Xiaoxu Chen <chenxiaoxu14@otcaix.iscas.ac.cn>
This commit is contained in:
Xiaoxu Chen 2015-10-09 18:24:32 +08:00
parent 6654b0e05f
commit 90a81f6af2
1 changed files with 8 additions and 16 deletions

View File

@ -1,11 +1,11 @@
package main package main
import ( import (
"bytes"
"os/exec" "os/exec"
"strings" "strings"
"time" "time"
"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check" "github.com/go-check/check"
) )
@ -13,7 +13,7 @@ func (s *DockerSuite) TestStatsNoStream(c *check.C) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
c.Assert(waitRun(id), check.IsNil) c.Assert(waitRun(id), checker.IsNil)
statsCmd := exec.Command(dockerBinary, "stats", "--no-stream", id) statsCmd := exec.Command(dockerBinary, "stats", "--no-stream", id)
type output struct { type output struct {
@ -29,12 +29,8 @@ func (s *DockerSuite) TestStatsNoStream(c *check.C) {
select { select {
case outerr := <-ch: case outerr := <-ch:
if outerr.err != nil { c.Assert(outerr.err, checker.IsNil, check.Commentf("Error running stats: %v", outerr.err))
c.Fatalf("Error running stats: %v", outerr.err) c.Assert(string(outerr.out), checker.Contains, id) //running container wasn't present in output
}
if !bytes.Contains(outerr.out, []byte(id)) {
c.Fatalf("running container wasn't present in output")
}
case <-time.After(3 * time.Second): case <-time.After(3 * time.Second):
statsCmd.Process.Kill() statsCmd.Process.Kill()
c.Fatalf("stats did not return immediately when not streaming") c.Fatalf("stats did not return immediately when not streaming")
@ -45,14 +41,10 @@ func (s *DockerSuite) TestStatsContainerNotFound(c *check.C) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _, err := dockerCmdWithError("stats", "notfound") out, _, err := dockerCmdWithError("stats", "notfound")
c.Assert(err, check.NotNil) c.Assert(err, checker.NotNil)
if !strings.Contains(out, "no such id: notfound") { c.Assert(out, checker.Contains, "no such id: notfound", check.Commentf("Expected to fail on not found container stats, got %q instead", out))
c.Fatalf("Expected to fail on not found container stats, got %q instead", out)
}
out, _, err = dockerCmdWithError("stats", "--no-stream", "notfound") out, _, err = dockerCmdWithError("stats", "--no-stream", "notfound")
c.Assert(err, check.NotNil) c.Assert(err, checker.NotNil)
if !strings.Contains(out, "no such id: notfound") { c.Assert(out, checker.Contains, "no such id: notfound", check.Commentf("Expected to fail on not found container stats with --no-stream, got %q instead", out))
c.Fatalf("Expected to fail on not found container stats with --no-stream, got %q instead", out)
}
} }