refactor stats to not use internal data structures

- refactor to make it easier to split the api in the future
 - addition to check the existing test case and make sure it contains
   some expected output

Signed-off-by: Morgan Bauer <mbauer@us.ibm.com>
This commit is contained in:
Morgan Bauer
2015-09-16 17:28:52 -07:00
parent 4a2c3733bd
commit 2d5d606fd3
3 changed files with 29 additions and 17 deletions
+16 -5
View File
@@ -1,6 +1,7 @@
package main
import (
"bytes"
"os/exec"
"strings"
"time"
@@ -15,18 +16,28 @@ func (s *DockerSuite) TestCliStatsNoStream(c *check.C) {
c.Assert(waitRun(id), check.IsNil)
statsCmd := exec.Command(dockerBinary, "stats", "--no-stream", id)
chErr := make(chan error)
type output struct {
out []byte
err error
}
ch := make(chan output)
go func() {
chErr <- statsCmd.Run()
out, err := statsCmd.Output()
ch <- output{out, err}
}()
select {
case err := <-chErr:
if err != nil {
c.Fatalf("Error running stats: %v", err)
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")
}
case <-time.After(3 * time.Second):
statsCmd.Process.Kill()
c.Fatalf("stats did not return immediately when not streaming")
}
}