Skip to content

Commit 6de1874

Browse files
aledbfclaude
andcommitted
test(cli): keep concurrent e2e runs off each other's Docker objects
Compose names its project and images after the workspace's basename, which t.TempDir makes 001 in every run; the dockerignore test used a fixed tag; and the build/up/exec tests used the repository's fixture folder, so runs from one checkout shared a container. Workspaces now have a unique basename, the fixtures are copied into one, and the dockerignore image name is unique. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c357b25 commit 6de1874

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

‎internal/cli/e2e_fixes_test.go‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func writeFixture(t *testing.T, files map[string]string) string {
1313
t.Helper()
14-
root := t.TempDir()
14+
root := uniqueWorkspace(t)
1515
for rel, content := range files {
1616
p := filepath.Join(root, rel)
1717
if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {
@@ -24,6 +24,17 @@ func writeFixture(t *testing.T, files map[string]string) string {
2424
return root
2525
}
2626

27+
// Concurrent runs share the Docker daemon, and a Compose project's name and
28+
// images come from the workspace's basename.
29+
func uniqueWorkspace(t *testing.T) string {
30+
t.Helper()
31+
root, err := os.MkdirTemp(t.TempDir(), "ws-")
32+
if err != nil {
33+
t.Fatal(err)
34+
}
35+
return root
36+
}
37+
2738
func dockerExec(t *testing.T, id, cmd string) string {
2839
t.Helper()
2940
out, err := exec.Command("docker", "exec", id, "sh", "-c", cmd).CombinedOutput()
@@ -165,11 +176,11 @@ func TestE2E_SiblingDockerignore(t *testing.T) {
165176
".devcontainer/secret.txt": "SUPERSECRET\n",
166177
})
167178

168-
buildOut := runCLI(t, "build", "--workspace-folder", ws, "--image-name", "e2e-dockerignore:test")
179+
image := uniqueImageName(t, "e2e-dockerignore")
180+
buildOut := runCLI(t, "build", "--workspace-folder", ws, "--image-name", image)
169181
assertOutcome(t, buildOut, "success")
170-
defer exec.Command("docker", "rmi", "-f", "e2e-dockerignore:test").Run()
171182

172-
out, err := exec.Command("docker", "run", "--rm", "e2e-dockerignore:test", "cat", "/dockerignore-result").CombinedOutput()
183+
out, err := exec.Command("docker", "run", "--rm", image, "cat", "/dockerignore-result").CombinedOutput()
173184
if err != nil {
174185
t.Fatalf("docker run failed: %v\n%s", err, out)
175186
}

‎internal/cli/e2e_test.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func TestE2E_BuildUpExec_Image(t *testing.T) {
2424
if _, err := os.Stat(fixture); os.IsNotExist(err) {
2525
t.Skip("fixtures not found")
2626
}
27+
fixture = copyFixture(t, fixture)
2728

2829
buildOut := runCLI(t, "build", "--workspace-folder", fixture)
2930
assertOutcome(t, buildOut, "success")
@@ -58,6 +59,7 @@ func TestE2E_BuildUpExec_Dockerfile(t *testing.T) {
5859
if _, err := os.Stat(fixture); os.IsNotExist(err) {
5960
t.Skip("fixtures not found")
6061
}
62+
fixture = copyFixture(t, fixture)
6163

6264
buildOut := runCLI(t, "build", "--workspace-folder", fixture)
6365
assertOutcome(t, buildOut, "success")
@@ -82,6 +84,15 @@ func TestE2E_BuildUpExec_Dockerfile(t *testing.T) {
8284
exec.Command("docker", "rm", "-f", containerID).Run()
8385
}
8486

87+
func copyFixture(t *testing.T, src string) string {
88+
t.Helper()
89+
dst := uniqueWorkspace(t)
90+
if err := os.CopyFS(dst, os.DirFS(src)); err != nil {
91+
t.Fatal(err)
92+
}
93+
return dst
94+
}
95+
8596
func TestE2E_ReadConfiguration_AllVariants(t *testing.T) {
8697
startFakeEngine(t, nil)
8798
fixtures := []struct {

0 commit comments

Comments
 (0)