Signed-off-by: Antonio Murdaca <runcom@linux.com>
| ... | ... |
@@ -3,6 +3,7 @@ package main |
| 3 | 3 |
import ( |
| 4 | 4 |
"encoding/json" |
| 5 | 5 |
"fmt" |
| 6 |
+ "net/http" |
|
| 6 | 7 |
"os/exec" |
| 7 | 8 |
"runtime" |
| 8 | 9 |
"strconv" |
| ... | ... |
@@ -13,7 +14,7 @@ import ( |
| 13 | 13 |
"github.com/go-check/check" |
| 14 | 14 |
) |
| 15 | 15 |
|
| 16 |
-func (s *DockerSuite) TestCliStatsNoStreamGetCpu(c *check.C) {
|
|
| 16 |
+func (s *DockerSuite) TestApiStatsNoStreamGetCpu(c *check.C) {
|
|
| 17 | 17 |
testRequires(c, DaemonIsLinux) |
| 18 | 18 |
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true;do echo 'Hello'; usleep 100000; done") |
| 19 | 19 |
|
| ... | ... |
@@ -39,7 +40,7 @@ func (s *DockerSuite) TestCliStatsNoStreamGetCpu(c *check.C) {
|
| 39 | 39 |
} |
| 40 | 40 |
} |
| 41 | 41 |
|
| 42 |
-func (s *DockerSuite) TestStoppedContainerStatsGoroutines(c *check.C) {
|
|
| 42 |
+func (s *DockerSuite) TestApiStatsStoppedContainerInGoroutines(c *check.C) {
|
|
| 43 | 43 |
testRequires(c, DaemonIsLinux) |
| 44 | 44 |
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo 1") |
| 45 | 45 |
id := strings.TrimSpace(out) |
| ... | ... |
@@ -75,7 +76,7 @@ func (s *DockerSuite) TestStoppedContainerStatsGoroutines(c *check.C) {
|
| 75 | 75 |
} |
| 76 | 76 |
} |
| 77 | 77 |
|
| 78 |
-func (s *DockerSuite) TestApiNetworkStats(c *check.C) {
|
|
| 78 |
+func (s *DockerSuite) TestApiStatsNetworkStats(c *check.C) {
|
|
| 79 | 79 |
testRequires(c, SameHostDaemon) |
| 80 | 80 |
testRequires(c, DaemonIsLinux) |
| 81 | 81 |
// Run container for 30 secs |
| ... | ... |
@@ -133,3 +134,15 @@ func getNetworkStats(c *check.C, id string) map[string]types.NetworkStats {
|
| 133 | 133 |
|
| 134 | 134 |
return st.Networks |
| 135 | 135 |
} |
| 136 |
+ |
|
| 137 |
+func (s *DockerSuite) TestApiStatsContainerNotFound(c *check.C) {
|
|
| 138 |
+ testRequires(c, DaemonIsLinux) |
|
| 139 |
+ |
|
| 140 |
+ status, _, err := sockRequest("GET", "/containers/nonexistent/stats", nil)
|
|
| 141 |
+ c.Assert(err, check.IsNil) |
|
| 142 |
+ c.Assert(status, check.Equals, http.StatusNotFound) |
|
| 143 |
+ |
|
| 144 |
+ status, _, err = sockRequest("GET", "/containers/nonexistent/stats?stream=0", nil)
|
|
| 145 |
+ c.Assert(err, check.IsNil) |
|
| 146 |
+ c.Assert(status, check.Equals, http.StatusNotFound) |
|
| 147 |
+} |
| ... | ... |
@@ -9,7 +9,7 @@ import ( |
| 9 | 9 |
"github.com/go-check/check" |
| 10 | 10 |
) |
| 11 | 11 |
|
| 12 |
-func (s *DockerSuite) TestCliStatsNoStream(c *check.C) {
|
|
| 12 |
+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) |
| ... | ... |
@@ -39,5 +39,20 @@ func (s *DockerSuite) TestCliStatsNoStream(c *check.C) {
|
| 39 | 39 |
statsCmd.Process.Kill() |
| 40 | 40 |
c.Fatalf("stats did not return immediately when not streaming")
|
| 41 | 41 |
} |
| 42 |
+} |
|
| 43 |
+ |
|
| 44 |
+func (s *DockerSuite) TestStatsContainerNotFound(c *check.C) {
|
|
| 45 |
+ testRequires(c, DaemonIsLinux) |
|
| 42 | 46 |
|
| 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 |
+ } |
|
| 52 |
+ |
|
| 53 |
+ 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 |
+ } |
|
| 43 | 58 |
} |