mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
add tests for 'images' subcommand
This commit is contained in:
parent
f4de9d919d
commit
3dba4022ad
2 changed files with 72 additions and 1 deletions
|
|
@ -619,7 +619,7 @@ func (srv *Server) CmdImages(stdin io.ReadCloser, stdout io.Writer, args ...stri
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(stdout, "digraph G {\n")
|
fmt.Fprintf(stdout, "digraph docker {\n")
|
||||||
|
|
||||||
var parentImage *Image
|
var parentImage *Image
|
||||||
var err error
|
var err error
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,77 @@ func cmdWait(srv *Server, container *Container) error {
|
||||||
return closeWrap(stdout, stdoutPipe)
|
return closeWrap(stdout, stdoutPipe)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cmdImages(srv *Server, args ...string) (string, error) {
|
||||||
|
stdout, stdoutPipe := io.Pipe()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
if err := srv.CmdImages(nil, stdoutPipe, args...); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// force the pipe closed, so that the code below gets an EOF
|
||||||
|
stdoutPipe.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
|
output, err := ioutil.ReadAll(stdout)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup pipes
|
||||||
|
return string(output), closeWrap(stdout, stdoutPipe)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestImages checks that 'docker images' displays information correctly
|
||||||
|
func TestImages(t *testing.T) {
|
||||||
|
|
||||||
|
runtime, err := newTestRuntime()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer nuke(runtime)
|
||||||
|
|
||||||
|
srv := &Server{runtime: runtime}
|
||||||
|
|
||||||
|
output, err := cmdImages(srv)
|
||||||
|
|
||||||
|
if !strings.Contains(output, "REPOSITORY") {
|
||||||
|
t.Fatal("'images' should have a header")
|
||||||
|
}
|
||||||
|
if !strings.Contains(output, "docker-ut") {
|
||||||
|
t.Fatal("'images' should show the docker-ut image")
|
||||||
|
}
|
||||||
|
if !strings.Contains(output, "e9aa60c60128") {
|
||||||
|
t.Fatal("'images' should show the docker-ut image id")
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err = cmdImages(srv, "-q")
|
||||||
|
|
||||||
|
if strings.Contains(output, "REPOSITORY") {
|
||||||
|
t.Fatal("'images -q' should not have a header")
|
||||||
|
}
|
||||||
|
if strings.Contains(output, "docker-ut") {
|
||||||
|
t.Fatal("'images' should not show the docker-ut image name")
|
||||||
|
}
|
||||||
|
if !strings.Contains(output, "e9aa60c60128") {
|
||||||
|
t.Fatal("'images' should show the docker-ut image id")
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err = cmdImages(srv, "-viz")
|
||||||
|
|
||||||
|
if !strings.HasPrefix(output, "digraph docker {") {
|
||||||
|
t.Fatal("'images -v' should start with the dot header")
|
||||||
|
}
|
||||||
|
if !strings.HasSuffix(output, "}\n") {
|
||||||
|
t.Fatal("'images -v' should end with a '}'")
|
||||||
|
}
|
||||||
|
if !strings.Contains(output, "base -> \"e9aa60c60128\" [style=invis]") {
|
||||||
|
t.Fatal("'images -v' should have the docker-ut image id node")
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo: add checks for -a
|
||||||
|
}
|
||||||
|
|
||||||
// TestRunHostname checks that 'docker run -h' correctly sets a custom hostname
|
// TestRunHostname checks that 'docker run -h' correctly sets a custom hostname
|
||||||
func TestRunHostname(t *testing.T) {
|
func TestRunHostname(t *testing.T) {
|
||||||
runtime, err := newTestRuntime()
|
runtime, err := newTestRuntime()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue