@@ -24,42 +24,36 @@ import (
2424 "testing"
2525
2626 "gotest.tools/v3/assert"
27- "gotest.tools/v3/icmd"
2827)
2928
3029// TestRunBuildOnce tests that services with pull_policy: build are only built once
3130// when using 'docker compose run', even when they are dependencies.
3231// This addresses a bug where dependencies were built twice: once in startDependencies
3332// and once in ensureImagesExists.
3433func TestRunBuildOnce (t * testing.T ) {
35- c := NewCLI (t )
34+ c := NewParallelCLI (t )
3635
3736 t .Run ("dependency with pull_policy build is built only once" , func (t * testing.T ) {
3837 projectName := randomProjectName ("build-once" )
39- res := c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once.yaml" , "down" , "--rmi" , "local" , "--remove-orphans" )
40- res .Assert (t , icmd .Success )
41-
42- res = c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once.yaml" , "run" , "--build" , "--rm" , "curl" )
43- res .Assert (t , icmd .Success )
38+ _ = c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once.yaml" , "down" , "--rmi" , "local" , "--remove-orphans" , "-v" )
39+ res := c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once.yaml" , "--verbose" , "run" , "--build" , "--rm" , "curl" )
4440
4541 // Count how many times nginx was built by looking for its unique RUN command output
46- nginxBuilds := strings .Count (res .Combined (), "Building nginx at" )
42+ nginxBuilds := strings .Count (res .Stdout (), "Building nginx at" )
4743
4844 // nginx should build exactly once, not twice
4945 assert .Equal (t , nginxBuilds , 1 , "nginx dependency should build once, but built %d times" , nginxBuilds )
50- assert .Assert (t , strings .Contains (res .Combined (), "curl service" ))
46+ assert .Assert (t , strings .Contains (res .Stdout (), "curl service" ))
5147
5248 c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once.yaml" , "down" , "--remove-orphans" )
5349 })
5450
5551 t .Run ("nested dependencies build only once each" , func (t * testing.T ) {
5652 projectName := randomProjectName ("build-nested" )
5753 _ = c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-nested.yaml" , "down" , "--rmi" , "local" , "--remove-orphans" , "-v" )
58-
5954 res := c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-nested.yaml" , "--verbose" , "run" , "--build" , "--rm" , "app" )
60- res .Assert (t , icmd .Success )
6155
62- output := res .Combined ()
56+ output := res .Stdout ()
6357
6458 dbBuildMarker := fmt .Sprintf ("naming to docker.io/library/%s-db" , projectName )
6559 apiBuildMarker := fmt .Sprintf ("naming to docker.io/library/%s-api" , projectName )
@@ -79,16 +73,13 @@ func TestRunBuildOnce(t *testing.T) {
7973
8074 t .Run ("service with no dependencies builds once" , func (t * testing.T ) {
8175 projectName := randomProjectName ("build-simple" )
82- res := c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-no-deps.yaml" , "down" , "--rmi" , "local" , "--remove-orphans" )
83- res .Assert (t , icmd .Success )
84-
85- res = c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-no-deps.yaml" , "run" , "--build" , "--rm" , "simple" )
86- res .Assert (t , icmd .Success )
76+ _ = c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-no-deps.yaml" , "down" , "--rmi" , "local" , "--remove-orphans" )
77+ res := c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-no-deps.yaml" , "run" , "--build" , "--rm" , "simple" )
8778
8879 // Should build exactly once
89- simpleBuilds := strings .Count (res .Combined (), "Simple service built at" )
80+ simpleBuilds := strings .Count (res .Stdout (), "Simple service built at" )
9081 assert .Equal (t , simpleBuilds , 1 , "simple should build once, built %d times" , simpleBuilds )
91- assert .Assert (t , strings .Contains (res .Combined (), "Simple service" ))
82+ assert .Assert (t , strings .Contains (res .Stdout (), "Simple service" ))
9283
9384 c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-no-deps.yaml" , "down" , "--remove-orphans" )
9485 })
0 commit comments