2015-02-13 11:45:04 -05:00
package main
import (
"os/exec"
"strings"
"time"
2015-10-09 06:24:32 -04:00
"github.com/docker/docker/pkg/integration/checker"
2015-02-13 11:45:04 -05:00
"github.com/go-check/check"
)
2015-09-17 12:20:25 -04:00
func ( s * DockerSuite ) TestStatsNoStream ( c * check . C ) {
2015-08-28 13:36:42 -04:00
testRequires ( c , DaemonIsLinux )
2015-07-20 02:44:22 -04:00
out , _ := dockerCmd ( c , "run" , "-d" , "busybox" , "top" )
2015-02-13 11:45:04 -05:00
id := strings . TrimSpace ( out )
2015-10-09 06:24:32 -04:00
c . Assert ( waitRun ( id ) , checker . IsNil )
2015-02-13 11:45:04 -05:00
statsCmd := exec . Command ( dockerBinary , "stats" , "--no-stream" , id )
2015-09-16 17:16:55 -04:00
type output struct {
out [ ] byte
err error
}
ch := make ( chan output )
2015-02-13 11:45:04 -05:00
go func ( ) {
2015-09-16 17:16:55 -04:00
out , err := statsCmd . Output ( )
ch <- output { out , err }
2015-02-13 11:45:04 -05:00
} ( )
select {
2015-09-16 17:16:55 -04:00
case outerr := <- ch :
2015-10-09 06:24:32 -04:00
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
2015-05-30 13:25:51 -04:00
case <- time . After ( 3 * time . Second ) :
2015-02-13 11:45:04 -05:00
statsCmd . Process . Kill ( )
c . Fatalf ( "stats did not return immediately when not streaming" )
}
2015-09-17 12:20:25 -04:00
}
func ( s * DockerSuite ) TestStatsContainerNotFound ( c * check . C ) {
testRequires ( c , DaemonIsLinux )
2015-09-16 17:16:55 -04:00
2015-09-17 12:20:25 -04:00
out , _ , err := dockerCmdWithError ( "stats" , "notfound" )
2015-10-09 06:24:32 -04:00
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 ) )
2015-09-17 12:20:25 -04:00
out , _ , err = dockerCmdWithError ( "stats" , "--no-stream" , "notfound" )
2015-10-09 06:24:32 -04:00
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 ) )
2015-02-13 11:45:04 -05:00
}