Skip to content

Commit d04b3f4

Browse files
ndeloofglours
authored andcommitted
e2e test covering multi-service rebuild with common resources
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent ed10804 commit d04b3f4

File tree

3 files changed

+79
-3
lines changed

3 files changed

+79
-3
lines changed

pkg/e2e/compose_run_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func TestLocalComposeRun(t *testing.T) {
162162
})
163163

164164
t.Run("--quiet-pull", func(t *testing.T) {
165-
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/quiet-pull.yaml", "down", "--rmi", "all")
165+
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/quiet-pull.yaml", "down", "--remove-orphans", "--rmi", "all")
166166
res.Assert(t, icmd.Success)
167167

168168
res = c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/quiet-pull.yaml", "run", "--quiet-pull", "backend")
@@ -171,12 +171,11 @@ func TestLocalComposeRun(t *testing.T) {
171171
})
172172

173173
t.Run("--pull", func(t *testing.T) {
174-
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/pull.yaml", "down", "--rmi", "all")
174+
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/pull.yaml", "down", "--remove-orphans", "--rmi", "all")
175175
res.Assert(t, icmd.Success)
176176

177177
res = c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/pull.yaml", "run", "--pull", "always", "backend")
178178
assert.Assert(t, strings.Contains(res.Combined(), "backend Pulling"), res.Combined())
179-
assert.Assert(t, strings.Contains(res.Combined(), "Download complete"), res.Combined())
180179
assert.Assert(t, strings.Contains(res.Combined(), "backend Pulled"), res.Combined())
181180
})
182181
}

pkg/e2e/fixtures/watch/rebuild.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
services:
2+
a:
3+
build:
4+
dockerfile_inline: |
5+
FROM nginx
6+
RUN mkdir /data
7+
COPY test /data/a
8+
develop:
9+
watch:
10+
- path: test
11+
action: rebuild
12+
b:
13+
build:
14+
dockerfile_inline: |
15+
FROM nginx
16+
RUN mkdir /data
17+
COPY test /data/b
18+
develop:
19+
watch:
20+
- path: test
21+
action: rebuild
22+
c:
23+
build:
24+
dockerfile_inline: |
25+
FROM nginx
26+
RUN mkdir /data
27+
COPY test /data/c
28+
develop:
29+
watch:
30+
- path: test
31+
action: rebuild

pkg/e2e/watch_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,49 @@ func TestWatchExec(t *testing.T) {
322322
})
323323
c.RunDockerComposeCmdNoCheck(t, "-p", projectName, "kill", "-s", "9")
324324
}
325+
326+
func TestWatchMultiServices(t *testing.T) {
327+
c := NewCLI(t)
328+
const projectName = "test_watch_rebuild"
329+
330+
defer c.cleanupWithDown(t, projectName)
331+
332+
tmpdir := t.TempDir()
333+
composeFilePath := filepath.Join(tmpdir, "compose.yaml")
334+
CopyFile(t, filepath.Join("fixtures", "watch", "rebuild.yaml"), composeFilePath)
335+
336+
testFile := filepath.Join(tmpdir, "test")
337+
require.NoError(t, os.WriteFile(testFile, []byte("test"), 0o600))
338+
339+
cmd := c.NewDockerComposeCmd(t, "-p", projectName, "-f", composeFilePath, "up", "--watch")
340+
buffer := bytes.NewBuffer(nil)
341+
cmd.Stdout = buffer
342+
watch := icmd.StartCmd(cmd)
343+
344+
poll.WaitOn(t, func(l poll.LogT) poll.Result {
345+
if strings.Contains(watch.Stdout(), "Attaching to ") {
346+
return poll.Success()
347+
}
348+
return poll.Continue("%v", watch.Stdout())
349+
})
350+
351+
waitRebuild := func(service string, expected string) {
352+
poll.WaitOn(t, func(l poll.LogT) poll.Result {
353+
cat := c.RunDockerComposeCmdNoCheck(t, "-p", projectName, "exec", service, "cat", "/data/"+service)
354+
if strings.Contains(cat.Stdout(), expected) {
355+
return poll.Success()
356+
}
357+
return poll.Continue("%v", cat.Combined())
358+
})
359+
}
360+
waitRebuild("a", "test")
361+
waitRebuild("b", "test")
362+
waitRebuild("c", "test")
363+
364+
require.NoError(t, os.WriteFile(testFile, []byte("updated"), 0o600))
365+
waitRebuild("a", "updated")
366+
waitRebuild("b", "updated")
367+
waitRebuild("c", "updated")
368+
369+
c.RunDockerComposeCmdNoCheck(t, "-p", projectName, "kill", "-s", "9")
370+
}

0 commit comments

Comments
 (0)