@@ -36,23 +36,27 @@ func TestRunBuildOnce(t *testing.T) {
3636
3737 t .Run ("dependency with pull_policy build is built only once" , func (t * testing.T ) {
3838 projectName := randomProjectName ("build-once" )
39- _ = c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once.yaml" , "down" , "--rmi" , "local" , "--remove-orphans" , "-v" )
40- res := c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once.yaml" , "--verbose" , "run" , "--build" , "--rm" , "curl" )
39+ composeFile := "./fixtures/run-test/build-once.yaml"
40+ t .Cleanup (func () {
41+ c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , composeFile , "down" , "--rmi" , "local" , "--remove-orphans" , "-v" )
42+ })
43+ res := c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , composeFile , "--verbose" , "run" , "--build" , "--rm" , "curl" )
4144
4245 output := res .Stdout ()
4346
4447 nginxBuilds := countServiceBuilds (output , projectName , "nginx" )
4548
4649 assert .Equal (t , nginxBuilds , 1 , "nginx should build once, built %d times\n Output:\n %s" , nginxBuilds , output )
4750 assert .Assert (t , strings .Contains (res .Stdout (), "curl service" ))
48-
49- c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once.yaml" , "down" , "--remove-orphans" )
5051 })
5152
5253 t .Run ("nested dependencies build only once each" , func (t * testing.T ) {
5354 projectName := randomProjectName ("build-nested" )
54- _ = c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-nested.yaml" , "down" , "--rmi" , "local" , "--remove-orphans" , "-v" )
55- res := c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-nested.yaml" , "--verbose" , "run" , "--build" , "--rm" , "app" )
55+ composeFile := "./fixtures/run-test/build-once-nested.yaml"
56+ t .Cleanup (func () {
57+ c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , composeFile , "down" , "--rmi" , "local" , "--remove-orphans" , "-v" )
58+ })
59+ res := c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , composeFile , "--verbose" , "run" , "--build" , "--rm" , "app" )
5660
5761 output := res .Stdout ()
5862
@@ -64,23 +68,22 @@ func TestRunBuildOnce(t *testing.T) {
6468 assert .Equal (t , apiBuilds , 1 , "api should build once, built %d times\n Output:\n %s" , apiBuilds , output )
6569 assert .Equal (t , appBuilds , 1 , "app should build once, built %d times\n Output:\n %s" , appBuilds , output )
6670 assert .Assert (t , strings .Contains (output , "App running" ))
67-
68- c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-nested.yaml" , "down" , "--rmi" , "local" , "--remove-orphans" , "-v" )
6971 })
7072
7173 t .Run ("service with no dependencies builds once" , func (t * testing.T ) {
7274 projectName := randomProjectName ("build-simple" )
73- _ = c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-no-deps.yaml" , "down" , "--rmi" , "local" , "--remove-orphans" )
74- res := c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-no-deps.yaml" , "run" , "--build" , "--rm" , "simple" )
75+ composeFile := "./fixtures/run-test/build-once-no-deps.yaml"
76+ t .Cleanup (func () {
77+ c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , composeFile , "down" , "--rmi" , "local" , "--remove-orphans" , "-v" )
78+ })
79+ res := c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , composeFile , "run" , "--build" , "--rm" , "simple" )
7580
7681 output := res .Stdout ()
7782
7883 simpleBuilds := countServiceBuilds (output , projectName , "simple" )
7984
8085 assert .Equal (t , simpleBuilds , 1 , "simple should build once, built %d times\n Output:\n %s" , simpleBuilds , output )
8186 assert .Assert (t , strings .Contains (res .Stdout (), "Simple service" ))
82-
83- c .RunDockerComposeCmd (t , "-p" , projectName , "-f" , "./fixtures/run-test/build-once-no-deps.yaml" , "down" , "--remove-orphans" )
8487 })
8588}
8689
0 commit comments