Skip to content

Commit 696051b

Browse files
committed
FIX docker-archive-public#2939 Integration tests for ls headers
Signed-off-by: David Gageot <david@gageot.net>
1 parent b496f61 commit 696051b

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

its/cli/ls_test.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,22 @@ func TestLs(t *testing.T) {
1111
defer test.TearDown()
1212

1313
test.Run("setup", func() {
14-
test.Machine("create -d none --url none --engine-label app=1 testmachine5").Should().Succeed()
15-
test.Machine("create -d none --url none --engine-label foo=bar --engine-label app=1 testmachine4").Should().Succeed()
16-
test.Machine("create -d none --url none testmachine3").Should().Succeed()
17-
test.Machine("create -d none --url none testmachine2").Should().Succeed()
18-
test.Machine("create -d none --url none testmachine").Should().Succeed()
14+
test.Machine("create -d none --url url5 --engine-label app=1 testmachine5").Should().Succeed()
15+
test.Machine("create -d none --url url4 --engine-label foo=bar --engine-label app=1 testmachine4").Should().Succeed()
16+
test.Machine("create -d none --url url3 testmachine3").Should().Succeed()
17+
test.Machine("create -d none --url url2 testmachine2").Should().Succeed()
18+
test.Machine("create -d none --url url1 testmachine").Should().Succeed()
19+
})
20+
21+
test.Run("ls: no filter", func() {
22+
test.Machine("ls").Should().Succeed().
23+
ContainLines(6).
24+
MatchLine(0, "NAME[ ]+ACTIVE[ ]+DRIVER[ ]+STATE[ ]+URL[ ]+SWARM[ ]+DOCKER[ ]+ERRORS").
25+
MatchLine(1, "testmachine[ ]+-[ ]+none[ ]+Running[ ]+url1[ ]+Unknown[ ]+Unable to query docker version: .*").
26+
MatchLine(2, "testmachine2[ ]+-[ ]+none[ ]+Running[ ]+url2[ ]+Unknown[ ]+Unable to query docker version: .*").
27+
MatchLine(3, "testmachine3[ ]+-[ ]+none[ ]+Running[ ]+url3[ ]+Unknown[ ]+Unable to query docker version: .*").
28+
MatchLine(4, "testmachine4[ ]+-[ ]+none[ ]+Running[ ]+url4[ ]+Unknown[ ]+Unable to query docker version: .*").
29+
MatchLine(5, "testmachine5[ ]+-[ ]+none[ ]+Running[ ]+url5[ ]+Unknown[ ]+Unable to query docker version: .*")
1930
})
2031

2132
test.Run("ls: filter on label", func() {

its/tester.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type Assertions interface {
5151

5252
ContainLine(index int, text string) Assertions
5353

54+
MatchLine(index int, template string) Assertions
55+
5456
EqualLine(index int, text string) Assertions
5557
}
5658

@@ -283,6 +285,22 @@ func (dmt *dockerMachineTest) ContainLine(index int, text string) Assertions {
283285
return dmt
284286
}
285287

288+
func (dmt *dockerMachineTest) MatchLine(index int, template string) Assertions {
289+
if dmt.fatal {
290+
return dmt
291+
}
292+
293+
if index >= len(dmt.lines) {
294+
return dmt.failExpected("at least %d lines\nGot %d", index+1, len(dmt.lines))
295+
}
296+
297+
if !regexp.MustCompile(template).MatchString(dmt.lines[index]) {
298+
return dmt.failExpected("line %d to match '%s'\nGot '%s'", index, template, dmt.lines[index])
299+
}
300+
301+
return dmt
302+
}
303+
286304
func (dmt *dockerMachineTest) EqualLine(index int, text string) Assertions {
287305
if dmt.fatal {
288306
return dmt

0 commit comments

Comments
 (0)