mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #16377 from runcom/add-stats-tests
integration-cli: add cli/api stats tests when container not found
This commit is contained in:
commit
52d7542195
2 changed files with 33 additions and 5 deletions
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
@ -13,7 +14,7 @@ import (
|
|||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestCliStatsNoStreamGetCpu(c *check.C) {
|
||||
func (s *DockerSuite) TestApiStatsNoStreamGetCpu(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true;do echo 'Hello'; usleep 100000; done")
|
||||
|
||||
|
@ -39,7 +40,7 @@ func (s *DockerSuite) TestCliStatsNoStreamGetCpu(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestStoppedContainerStatsGoroutines(c *check.C) {
|
||||
func (s *DockerSuite) TestApiStatsStoppedContainerInGoroutines(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo 1")
|
||||
id := strings.TrimSpace(out)
|
||||
|
@ -75,7 +76,7 @@ func (s *DockerSuite) TestStoppedContainerStatsGoroutines(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestApiNetworkStats(c *check.C) {
|
||||
func (s *DockerSuite) TestApiStatsNetworkStats(c *check.C) {
|
||||
testRequires(c, SameHostDaemon)
|
||||
testRequires(c, DaemonIsLinux)
|
||||
// Run container for 30 secs
|
||||
|
@ -133,3 +134,15 @@ func getNetworkStats(c *check.C, id string) map[string]types.NetworkStats {
|
|||
|
||||
return st.Networks
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestApiStatsContainerNotFound(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
status, _, err := sockRequest("GET", "/containers/nonexistent/stats", nil)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusNotFound)
|
||||
|
||||
status, _, err = sockRequest("GET", "/containers/nonexistent/stats?stream=0", nil)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusNotFound)
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestCliStatsNoStream(c *check.C) {
|
||||
func (s *DockerSuite) TestStatsNoStream(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
||||
id := strings.TrimSpace(out)
|
||||
|
@ -39,5 +39,20 @@ func (s *DockerSuite) TestCliStatsNoStream(c *check.C) {
|
|||
statsCmd.Process.Kill()
|
||||
c.Fatalf("stats did not return immediately when not streaming")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue