adding test for "images -viz"
This commit is contained in:
parent
059bb7a262
commit
d9fe0647cb
2 changed files with 49 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue