Browse code

update integration-cli/docker_cli_stats_test.go use Assert statement part of #16756

Signed-off-by: Xiaoxu Chen <chenxiaoxu14@otcaix.iscas.ac.cn>

Xiaoxu Chen authored on 2015/10/09 19:24:32
Showing 1 changed files
... ...
@@ -1,11 +1,11 @@
1 1
 package main
2 2
 
3 3
 import (
4
-	"bytes"
5 4
 	"os/exec"
6 5
 	"strings"
7 6
 	"time"
8 7
 
8
+	"github.com/docker/docker/pkg/integration/checker"
9 9
 	"github.com/go-check/check"
10 10
 )
11 11
 
... ...
@@ -13,7 +13,7 @@ func (s *DockerSuite) TestStatsNoStream(c *check.C) {
13 13
 	testRequires(c, DaemonIsLinux)
14 14
 	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
15 15
 	id := strings.TrimSpace(out)
16
-	c.Assert(waitRun(id), check.IsNil)
16
+	c.Assert(waitRun(id), checker.IsNil)
17 17
 
18 18
 	statsCmd := exec.Command(dockerBinary, "stats", "--no-stream", id)
19 19
 	type output struct {
... ...
@@ -29,12 +29,8 @@ func (s *DockerSuite) TestStatsNoStream(c *check.C) {
29 29
 
30 30
 	select {
31 31
 	case outerr := <-ch:
32
-		if outerr.err != nil {
33
-			c.Fatalf("Error running stats: %v", outerr.err)
34
-		}
35
-		if !bytes.Contains(outerr.out, []byte(id)) {
36
-			c.Fatalf("running container wasn't present in output")
37
-		}
32
+		c.Assert(outerr.err, checker.IsNil, check.Commentf("Error running stats: %v", outerr.err))
33
+		c.Assert(string(outerr.out), checker.Contains, id) //running container wasn't present in output
38 34
 	case <-time.After(3 * time.Second):
39 35
 		statsCmd.Process.Kill()
40 36
 		c.Fatalf("stats did not return immediately when not streaming")
... ...
@@ -45,14 +41,10 @@ func (s *DockerSuite) TestStatsContainerNotFound(c *check.C) {
45 45
 	testRequires(c, DaemonIsLinux)
46 46
 
47 47
 	out, _, err := dockerCmdWithError("stats", "notfound")
48
-	c.Assert(err, check.NotNil)
49
-	if !strings.Contains(out, "no such id: notfound") {
50
-		c.Fatalf("Expected to fail on not found container stats, got %q instead", out)
51
-	}
48
+	c.Assert(err, checker.NotNil)
49
+	c.Assert(out, checker.Contains, "no such id: notfound", check.Commentf("Expected to fail on not found container stats, got %q instead", out))
52 50
 
53 51
 	out, _, err = dockerCmdWithError("stats", "--no-stream", "notfound")
54
-	c.Assert(err, check.NotNil)
55
-	if !strings.Contains(out, "no such id: notfound") {
56
-		c.Fatalf("Expected to fail on not found container stats with --no-stream, got %q instead", out)
57
-	}
52
+	c.Assert(err, checker.NotNil)
53
+	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))
58 54
 }