Merge pull request #2940 from dgageot/2939-it-ls-headers

FIX #2939 Integration tests for ls headers
This commit is contained in:
Jean-Laurent de Morlhon 2016-01-27 10:20:36 +01:00
commit 8f1877e2be
2 changed files with 34 additions and 5 deletions

View File

@ -11,11 +11,22 @@ func TestLs(t *testing.T) {
defer test.TearDown() defer test.TearDown()
test.Run("setup", func() { test.Run("setup", func() {
test.Machine("create -d none --url none --engine-label app=1 testmachine5").Should().Succeed() test.Machine("create -d none --url url5 --engine-label app=1 testmachine5").Should().Succeed()
test.Machine("create -d none --url none --engine-label foo=bar --engine-label app=1 testmachine4").Should().Succeed() test.Machine("create -d none --url url4 --engine-label foo=bar --engine-label app=1 testmachine4").Should().Succeed()
test.Machine("create -d none --url none testmachine3").Should().Succeed() test.Machine("create -d none --url url3 testmachine3").Should().Succeed()
test.Machine("create -d none --url none testmachine2").Should().Succeed() test.Machine("create -d none --url url2 testmachine2").Should().Succeed()
test.Machine("create -d none --url none testmachine").Should().Succeed() test.Machine("create -d none --url url1 testmachine").Should().Succeed()
})
test.Run("ls: no filter", func() {
test.Machine("ls").Should().Succeed().
ContainLines(6).
MatchLine(0, "NAME[ ]+ACTIVE[ ]+DRIVER[ ]+STATE[ ]+URL[ ]+SWARM[ ]+DOCKER[ ]+ERRORS").
MatchLine(1, "testmachine[ ]+-[ ]+none[ ]+Running[ ]+url1[ ]+Unknown[ ]+Unable to query docker version: .*").
MatchLine(2, "testmachine2[ ]+-[ ]+none[ ]+Running[ ]+url2[ ]+Unknown[ ]+Unable to query docker version: .*").
MatchLine(3, "testmachine3[ ]+-[ ]+none[ ]+Running[ ]+url3[ ]+Unknown[ ]+Unable to query docker version: .*").
MatchLine(4, "testmachine4[ ]+-[ ]+none[ ]+Running[ ]+url4[ ]+Unknown[ ]+Unable to query docker version: .*").
MatchLine(5, "testmachine5[ ]+-[ ]+none[ ]+Running[ ]+url5[ ]+Unknown[ ]+Unable to query docker version: .*")
}) })
test.Run("ls: filter on label", func() { test.Run("ls: filter on label", func() {

View File

@ -51,6 +51,8 @@ type Assertions interface {
ContainLine(index int, text string) Assertions ContainLine(index int, text string) Assertions
MatchLine(index int, template string) Assertions
EqualLine(index int, text string) Assertions EqualLine(index int, text string) Assertions
} }
@ -283,6 +285,22 @@ func (dmt *dockerMachineTest) ContainLine(index int, text string) Assertions {
return dmt return dmt
} }
func (dmt *dockerMachineTest) MatchLine(index int, template string) Assertions {
if dmt.fatal {
return dmt
}
if index >= len(dmt.lines) {
return dmt.failExpected("at least %d lines\nGot %d", index+1, len(dmt.lines))
}
if !regexp.MustCompile(template).MatchString(dmt.lines[index]) {
return dmt.failExpected("line %d to match '%s'\nGot '%s'", index, template, dmt.lines[index])
}
return dmt
}
func (dmt *dockerMachineTest) EqualLine(index int, text string) Assertions { func (dmt *dockerMachineTest) EqualLine(index int, text string) Assertions {
if dmt.fatal { if dmt.fatal {
return dmt return dmt