mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-05 05:01:28 +00:00
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:
@@ -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")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user