@@ -19,6 +19,7 @@ package compose
19
19
import (
20
20
"fmt"
21
21
"io"
22
+ "os"
22
23
"strings"
23
24
"testing"
24
25
"time"
@@ -499,6 +500,12 @@ func TestComposeUpProfile(t *testing.T) {
499
500
serviceRegular := testutil .Identifier (t ) + "-regular"
500
501
serviceProfiled := testutil .Identifier (t ) + "-profiled"
501
502
503
+ // write the env.common file to tmpdir
504
+ tmpDir := t .TempDir ()
505
+ envFilePath := fmt .Sprintf ("%s/env.common" , tmpDir )
506
+ err := os .WriteFile (envFilePath , []byte ("TEST_ENV_INJECTION=WORKS\n " ), 0644 )
507
+ assert .NilError (t , err )
508
+
502
509
dockerComposeYAML := fmt .Sprintf (`
503
510
services:
504
511
%s:
@@ -508,7 +515,9 @@ services:
508
515
image: %[3]s
509
516
profiles:
510
517
- test-profile
511
- ` , serviceRegular , serviceProfiled , testutil .NginxAlpineImage )
518
+ env_file:
519
+ - %[4]s
520
+ ` , serviceRegular , serviceProfiled , testutil .NginxAlpineImage , envFilePath )
512
521
513
522
// * Test with profile
514
523
// Should run both the services:
@@ -521,6 +530,10 @@ services:
521
530
psCmd := base .Cmd ("ps" , "-a" , "--format={{.Names}}" )
522
531
psCmd .AssertOutContains (serviceRegular )
523
532
psCmd .AssertOutContains (serviceProfiled )
533
+
534
+ execCmd := base .ComposeCmd ("-f" , comp1 .YAMLFullPath (), "exec" , serviceProfiled , "env" )
535
+ execCmd .AssertOutContains ("TEST_ENV_INJECTION=WORKS" )
536
+
524
537
base .ComposeCmd ("-f" , comp1 .YAMLFullPath (), "--profile" , "test-profile" , "down" , "-v" ).AssertOK ()
525
538
526
539
// * Test without profile
0 commit comments