From d9fe0647cb464ccd6f79ac33fb1d1ac56441f6b0 Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Sun, 13 Oct 2013 22:36:05 +0000 Subject: [PATCH] adding test for "images -viz" --- commands_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ runtime_test.go | 1 + 2 files changed, 49 insertions(+) diff --git a/commands_test.go b/commands_test.go index 1ec005bdd1..28a19d2af8 100644 --- a/commands_test.go +++ b/commands_test.go @@ -6,6 +6,7 @@ import ( "github.com/dotcloud/docker/utils" "io" "io/ioutil" + "regexp" "strings" "testing" "time" @@ -699,3 +700,50 @@ func TestRunErrorBindNonExistingSource(t *testing.T) { <-c }) } + +func TestImagesViz(t *testing.T) { + stdout, stdoutPipe := io.Pipe() + + cli := NewDockerCli(nil, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) + defer cleanup(globalRuntime) + + c := make(chan struct{}) + go func() { + defer close(c) + if err := cli.CmdImages("-viz"); err != nil { + t.Fatal(err) + } + stdoutPipe.Close() + }() + + setTimeout(t, "Reading command output time out", 2*time.Second, func() { + cmdOutputBytes, err := ioutil.ReadAll(bufio.NewReader(stdout)) + if err != nil { + t.Fatal(err) + } + cmdOutput := string(cmdOutputBytes) + + regexpStrings := []string{ + "digraph docker {", + fmt.Sprintf("base -> \"%s\" \\[style=invis]", unitTestImageIDShort), + fmt.Sprintf("label=\"%s\\\\n%s:latest\"", unitTestImageIDShort, unitTestImageName), + "base \\[style=invisible]", + } + + compiledRegexps := []*regexp.Regexp{} + for _, regexpString := range regexpStrings { + regexp, err := regexp.Compile(regexpString) + if err != nil { + fmt.Println("Error in regex string: ", err) + return + } + compiledRegexps = append(compiledRegexps, regexp) + } + + for _, regexp := range compiledRegexps { + if !regexp.MatchString(cmdOutput) { + t.Fatalf("images -viz content '%s' did not match regexp '%s'", cmdOutput, regexp) + } + } + }) +} diff --git a/runtime_test.go b/runtime_test.go index 4e46b7b6d0..e61f63d495 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -22,6 +22,7 @@ import ( const ( unitTestImageName = "docker-test-image" unitTestImageID = "83599e29c455eb719f77d799bc7c51521b9551972f5a850d7ad265bc1b5292f6" // 1.0 + unitTestImageIDShort = "83599e29c455" unitTestNetworkBridge = "testdockbr0" unitTestStoreBase = "/var/lib/docker/unit-tests" testDaemonAddr = "127.0.0.1:4270"