Skip to content

Commit 0db6dfe

Browse files
make compose pull tests more expressive
Signed-off-by: Vedant Koditkar <[email protected]>
1 parent e623b5c commit 0db6dfe

File tree

5 files changed

+60
-21
lines changed

5 files changed

+60
-21
lines changed

pkg/e2e/compose_test.go

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,31 +122,49 @@ func TestLocalComposeUp(t *testing.T) {
122122
func TestComposePull(t *testing.T) {
123123
c := NewParallelCLI(t)
124124

125-
res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/simple-composefile", "pull")
126-
output := res.Combined()
127-
128-
expected := []string{
129-
"Skipped - No image to be pulled",
130-
"Skipped - Image is already present locally",
131-
"Skipped - Image is already being pulled by",
132-
"simple Pulled",
133-
"another Pulled",
134-
}
135-
136-
assert.Assert(t, contains(output, expected))
137-
}
125+
t.Run("Verify image pulled", func(t *testing.T) {
126+
// cleanup existing images
127+
c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/simple", "down", "--rmi", "all")
128+
129+
res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/simple", "pull")
130+
output := res.Combined()
131+
132+
assert.Assert(t, strings.Contains(output, "simple Pulled"))
133+
assert.Assert(t, strings.Contains(output, "another Pulled"))
134+
})
135+
136+
t.Run("Verify a image is pulled once", func(t *testing.T) {
137+
// cleanup existing images
138+
c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/duplicate-images", "down", "--rmi", "all")
138139

139-
func contains(str string, array []string) bool {
140-
found := false
140+
res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/duplicate-images", "pull")
141+
output := res.Combined()
141142

142-
for _, val := range array {
143-
if strings.Contains(str, val) {
144-
found = true
145-
break
143+
if strings.Contains(output, "another Pulled") {
144+
assert.Assert(t, strings.Contains(output, "another Pulled"))
145+
assert.Assert(t, strings.Contains(output, "Skipped - Image is already being pulled by another"))
146+
} else {
147+
assert.Assert(t, strings.Contains(output, "simple Pulled"))
148+
assert.Assert(t, strings.Contains(output, "Skipped - Image is already being pulled by simple"))
146149
}
147-
}
150+
})
148151

149-
return found
152+
t.Run("Verify skipped pull if image is already present locally", func(t *testing.T) {
153+
// make sure the requied image is present
154+
c.RunDockerCmd(t, "pull", "alpine")
155+
156+
res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/image-present-locally", "pull")
157+
output := res.Combined()
158+
159+
assert.Assert(t, strings.Contains(output, "Skipped - Image is already present locally"))
160+
})
161+
162+
t.Run("Verify skipped no image to be pulled", func(t *testing.T) {
163+
res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/no-image-name-given", "pull")
164+
output := res.Combined()
165+
166+
assert.Assert(t, strings.Contains(output, "Skipped - No image to be pulled"))
167+
})
150168
}
151169

152170
func TestDownComposefileInParentFolder(t *testing.T) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
simple:
3+
image: alpine:3.13
4+
command: top
5+
another:
6+
image: alpine:3.13
7+
command: top
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
simple:
3+
image: alpine
4+
command: top
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
services:
2+
no-image-service:
3+
build: .
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
simple:
3+
image: alpine:3.14
4+
command: top
5+
another:
6+
image: alpine:3.15
7+
command: top

0 commit comments

Comments
 (0)