зеркало из https://github.com/microsoft/docker.git
Merge pull request #16881 from cxxly/16756-refactor-docker_cli_stats_test
update integration-cli/docker_cli_stats_test.go use Assert statement
This commit is contained in:
Коммит
a77d80d9d1
|
@ -1,11 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
|
@ -13,7 +13,7 @@ func (s *DockerSuite) TestStatsNoStream(c *check.C) {
|
|||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
||||
id := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(id), check.IsNil)
|
||||
c.Assert(waitRun(id), checker.IsNil)
|
||||
|
||||
statsCmd := exec.Command(dockerBinary, "stats", "--no-stream", id)
|
||||
type output struct {
|
||||
|
@ -29,12 +29,8 @@ func (s *DockerSuite) TestStatsNoStream(c *check.C) {
|
|||
|
||||
select {
|
||||
case outerr := <-ch:
|
||||
if outerr.err != nil {
|
||||
c.Fatalf("Error running stats: %v", outerr.err)
|
||||
}
|
||||
if !bytes.Contains(outerr.out, []byte(id)) {
|
||||
c.Fatalf("running container wasn't present in output")
|
||||
}
|
||||
c.Assert(outerr.err, checker.IsNil, check.Commentf("Error running stats: %v", outerr.err))
|
||||
c.Assert(string(outerr.out), checker.Contains, id) //running container wasn't present in output
|
||||
case <-time.After(3 * time.Second):
|
||||
statsCmd.Process.Kill()
|
||||
c.Fatalf("stats did not return immediately when not streaming")
|
||||
|
@ -45,14 +41,10 @@ func (s *DockerSuite) TestStatsContainerNotFound(c *check.C) {
|
|||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
out, _, err := dockerCmdWithError("stats", "notfound")
|
||||
c.Assert(err, check.NotNil)
|
||||
if !strings.Contains(out, "no such id: notfound") {
|
||||
c.Fatalf("Expected to fail on not found container stats, got %q instead", out)
|
||||
}
|
||||
c.Assert(err, checker.NotNil)
|
||||
c.Assert(out, checker.Contains, "no such id: notfound", check.Commentf("Expected to fail on not found container stats, got %q instead", out))
|
||||
|
||||
out, _, err = dockerCmdWithError("stats", "--no-stream", "notfound")
|
||||
c.Assert(err, check.NotNil)
|
||||
if !strings.Contains(out, "no such id: notfound") {
|
||||
c.Fatalf("Expected to fail on not found container stats with --no-stream, got %q instead", out)
|
||||
}
|
||||
c.Assert(err, checker.NotNil)
|
||||
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))
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче