From 19571c2c816babe54fbbcec129ccef85027010ed Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Mon, 3 Mar 2025 16:55:53 +0100 Subject: [PATCH] e2e test for watch.include Signed-off-by: Nicolas De Loof --- pkg/e2e/fixtures/watch/include.yaml | 12 ++++++++++ pkg/e2e/watch_test.go | 37 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 pkg/e2e/fixtures/watch/include.yaml diff --git a/pkg/e2e/fixtures/watch/include.yaml b/pkg/e2e/fixtures/watch/include.yaml new file mode 100644 index 000000000..ccd9d4504 --- /dev/null +++ b/pkg/e2e/fixtures/watch/include.yaml @@ -0,0 +1,12 @@ +services: + a: + build: + dockerfile_inline: | + FROM nginx + RUN mkdir /data/ + develop: + watch: + - path: . + include: A.* + target: /data/ + action: sync diff --git a/pkg/e2e/watch_test.go b/pkg/e2e/watch_test.go index 1a8c92cc5..5c4db4765 100644 --- a/pkg/e2e/watch_test.go +++ b/pkg/e2e/watch_test.go @@ -368,3 +368,40 @@ func TestWatchMultiServices(t *testing.T) { c.RunDockerComposeCmdNoCheck(t, "-p", projectName, "kill", "-s", "9") } + +func TestWatchIncludes(t *testing.T) { + c := NewCLI(t) + const projectName = "test_watch_includes" + + defer c.cleanupWithDown(t, projectName) + + tmpdir := t.TempDir() + composeFilePath := filepath.Join(tmpdir, "compose.yaml") + CopyFile(t, filepath.Join("fixtures", "watch", "include.yaml"), composeFilePath) + + cmd := c.NewDockerComposeCmd(t, "-p", projectName, "-f", composeFilePath, "up", "--watch") + buffer := bytes.NewBuffer(nil) + cmd.Stdout = buffer + watch := icmd.StartCmd(cmd) + + poll.WaitOn(t, func(l poll.LogT) poll.Result { + if strings.Contains(watch.Stdout(), "Attaching to ") { + return poll.Success() + } + return poll.Continue("%v", watch.Stdout()) + }) + + require.NoError(t, os.WriteFile(filepath.Join(tmpdir, "B.test"), []byte("test"), 0o600)) + require.NoError(t, os.WriteFile(filepath.Join(tmpdir, "A.test"), []byte("test"), 0o600)) + + poll.WaitOn(t, func(l poll.LogT) poll.Result { + cat := c.RunDockerComposeCmdNoCheck(t, "-p", projectName, "exec", "a", "ls", "/data/") + if strings.Contains(cat.Stdout(), "A.test") { + assert.Check(t, !strings.Contains(cat.Stdout(), "B.test")) + return poll.Success() + } + return poll.Continue("%v", cat.Combined()) + }) + + c.RunDockerComposeCmdNoCheck(t, "-p", projectName, "kill", "-s", "9") +}