mirror of
https://github.com/docker/compose.git
synced 2025-11-11 17:30:04 +01:00
fix compose_run_build_once_test.go
Signed-off-by: Suleiman Dibirov <idsulik@gmail.com> (cherry picked from commit c416ea70361a479e61e9be7ac1fb910c13b478c0) Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
parent
3de9b0cc71
commit
19351bbd7d
@ -17,6 +17,9 @@
|
|||||||
package e2e
|
package e2e
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -32,11 +35,11 @@ func TestRunBuildOnce(t *testing.T) {
|
|||||||
c := NewParallelCLI(t)
|
c := NewParallelCLI(t)
|
||||||
|
|
||||||
t.Run("dependency with pull_policy build is built only once", func(t *testing.T) {
|
t.Run("dependency with pull_policy build is built only once", func(t *testing.T) {
|
||||||
projectName := "e2e-run-build-once-single"
|
projectName := randomProjectName("build-once")
|
||||||
res := c.RunDockerComposeCmd(t, "-p", projectName, "-f", "./fixtures/run-test/build-once.yaml", "down", "--rmi", "local", "--remove-orphans")
|
res := c.RunDockerComposeCmd(t, "-p", projectName, "-f", "./fixtures/run-test/build-once.yaml", "down", "--rmi", "local", "--remove-orphans")
|
||||||
res.Assert(t, icmd.Success)
|
res.Assert(t, icmd.Success)
|
||||||
|
|
||||||
res = c.RunDockerComposeCmd(t, "-p", projectName, "-f", "./fixtures/run-test/build-once.yaml", "run", "--rm", "curl")
|
res = c.RunDockerComposeCmd(t, "-p", projectName, "-f", "./fixtures/run-test/build-once.yaml", "run", "--build", "--rm", "curl")
|
||||||
res.Assert(t, icmd.Success)
|
res.Assert(t, icmd.Success)
|
||||||
|
|
||||||
// Count how many times nginx was built by looking for its unique RUN command output
|
// Count how many times nginx was built by looking for its unique RUN command output
|
||||||
@ -50,11 +53,11 @@ func TestRunBuildOnce(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("nested dependencies build only once each", func(t *testing.T) {
|
t.Run("nested dependencies build only once each", func(t *testing.T) {
|
||||||
projectName := "e2e-run-build-once-nested"
|
projectName := randomProjectName("build-nested")
|
||||||
res := c.RunDockerComposeCmd(t, "-p", projectName, "-f", "./fixtures/run-test/build-once-nested.yaml", "down", "--rmi", "local", "--remove-orphans")
|
res := c.RunDockerComposeCmd(t, "-p", projectName, "-f", "./fixtures/run-test/build-once-nested.yaml", "down", "--rmi", "local", "--remove-orphans")
|
||||||
res.Assert(t, icmd.Success)
|
res.Assert(t, icmd.Success)
|
||||||
|
|
||||||
res = c.RunDockerComposeCmd(t, "-p", projectName, "-f", "./fixtures/run-test/build-once-nested.yaml", "run", "--rm", "app")
|
res = c.RunDockerComposeCmd(t, "-p", projectName, "-f", "./fixtures/run-test/build-once-nested.yaml", "run", "--build", "--rm", "app")
|
||||||
res.Assert(t, icmd.Success)
|
res.Assert(t, icmd.Success)
|
||||||
|
|
||||||
output := res.Combined()
|
output := res.Combined()
|
||||||
@ -73,11 +76,11 @@ func TestRunBuildOnce(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("service with no dependencies builds once", func(t *testing.T) {
|
t.Run("service with no dependencies builds once", func(t *testing.T) {
|
||||||
projectName := "e2e-run-build-once-no-deps"
|
projectName := randomProjectName("build-simple")
|
||||||
res := c.RunDockerComposeCmd(t, "-p", projectName, "-f", "./fixtures/run-test/build-once-no-deps.yaml", "down", "--rmi", "local", "--remove-orphans")
|
res := c.RunDockerComposeCmd(t, "-p", projectName, "-f", "./fixtures/run-test/build-once-no-deps.yaml", "down", "--rmi", "local", "--remove-orphans")
|
||||||
res.Assert(t, icmd.Success)
|
res.Assert(t, icmd.Success)
|
||||||
|
|
||||||
res = c.RunDockerComposeCmd(t, "-p", projectName, "-f", "./fixtures/run-test/build-once-no-deps.yaml", "run", "--rm", "simple")
|
res = c.RunDockerComposeCmd(t, "-p", projectName, "-f", "./fixtures/run-test/build-once-no-deps.yaml", "run", "--build", "--rm", "simple")
|
||||||
res.Assert(t, icmd.Success)
|
res.Assert(t, icmd.Success)
|
||||||
|
|
||||||
// Should build exactly once
|
// Should build exactly once
|
||||||
@ -88,3 +91,11 @@ func TestRunBuildOnce(t *testing.T) {
|
|||||||
c.RunDockerComposeCmd(t, "-p", projectName, "-f", "./fixtures/run-test/build-once-no-deps.yaml", "down", "--remove-orphans")
|
c.RunDockerComposeCmd(t, "-p", projectName, "-f", "./fixtures/run-test/build-once-no-deps.yaml", "down", "--remove-orphans")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// randomProjectName generates a unique project name for parallel test execution
|
||||||
|
// Format: prefix-<8 random hex chars> (e.g., "build-once-3f4a9b2c")
|
||||||
|
func randomProjectName(prefix string) string {
|
||||||
|
b := make([]byte, 4) // 4 bytes = 8 hex chars
|
||||||
|
rand.Read(b) //nolint:errcheck
|
||||||
|
return fmt.Sprintf("%s-%s", prefix, hex.EncodeToString(b))
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user