1717package e2e
1818
1919import (
20+ "crypto/rand"
21+ "encoding/hex"
22+ "fmt"
2023 "strings"
2124 "testing"
2225
@@ -32,11 +35,11 @@ func TestRunBuildOnce(t *testing.T) {
3235 c := NewParallelCLI (t )
3336
3437 t .Run ("dependency with pull_policy build is built only once" , func (t * testing.T ) {
35- projectName := "e2e-run- build-once-single"
38+ projectName := randomProjectName ( " build-once" )
3639 res := c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once.yaml" , "down" , "--rmi" , "local" , "--remove-orphans" )
3740 res .Assert (t , icmd .Success )
3841
39- res = c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once.yaml" , "run" , "--rm" , "curl" )
42+ res = c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once.yaml" , "run" , "--build" , "-- rm" , "curl" )
4043 res .Assert (t , icmd .Success )
4144
4245 // Count how many times nginx was built by looking for its unique RUN command output
@@ -50,11 +53,11 @@ func TestRunBuildOnce(t *testing.T) {
5053 })
5154
5255 t .Run ("nested dependencies build only once each" , func (t * testing.T ) {
53- projectName := "e2e-run- build-once- nested"
56+ projectName := randomProjectName ( " build-nested")
5457 res := c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-nested.yaml" , "down" , "--rmi" , "local" , "--remove-orphans" )
5558 res .Assert (t , icmd .Success )
5659
57- res = c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-nested.yaml" , "run" , "--rm" , "app" )
60+ res = c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-nested.yaml" , "run" , "--build" , "-- rm" , "app" )
5861 res .Assert (t , icmd .Success )
5962
6063 output := res .Combined ()
@@ -73,11 +76,11 @@ func TestRunBuildOnce(t *testing.T) {
7376 })
7477
7578 t .Run ("service with no dependencies builds once" , func (t * testing.T ) {
76- projectName := "e2e-run- build-once-no-deps"
79+ projectName := randomProjectName ( " build-simple" )
7780 res := c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-no-deps.yaml" , "down" , "--rmi" , "local" , "--remove-orphans" )
7881 res .Assert (t , icmd .Success )
7982
80- res = c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-no-deps.yaml" , "run" , "--rm" , "simple" )
83+ res = c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-no-deps.yaml" , "run" , "--build" , "-- rm" , "simple" )
8184 res .Assert (t , icmd .Success )
8285
8386 // Should build exactly once
@@ -88,3 +91,11 @@ func TestRunBuildOnce(t *testing.T) {
8891 c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-no-deps.yaml" , "down" , "--remove-orphans" )
8992 })
9093}
94+
95+ // randomProjectName generates a unique project name for parallel test execution
96+ // Format: prefix-<8 random hex chars> (e.g., "build-once-3f4a9b2c")
97+ func randomProjectName (prefix string ) string {
98+ b := make ([]byte , 4 ) // 4 bytes = 8 hex chars
99+ rand .Read (b ) //nolint:errcheck
100+ return fmt .Sprintf ("%s-%s" , prefix , hex .EncodeToString (b ))
101+ }
0 commit comments