diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index 02bf70b..c51251a 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -4,6 +4,7 @@ package e2e import ( + "fmt" "os" "path/filepath" "testing" @@ -48,7 +49,18 @@ func TestE2e(t *testing.T) { vmName := "fedora" - nerdctlOpt, err := option.New([]string{subject, "shell", vmName, "sudo", "-E", "nerdctl"}) + var passThroughEnvVars []string + + // Pass through COMPOSE_FILE for compose build test suite. + for _, envVar := range []string{"COMPOSE_FILE"} { + if val, ok := os.LookupEnv(envVar); ok { + passThroughEnvVars = append(passThroughEnvVars, fmt.Sprintf("%s=%s", envVar, val)) + } + } + + // Add -E to sudo command in order to preserve existing environment variables, more info: + // https://stackoverflow.com/questions/8633461/how-to-keep-environment-variables-when-using-sudo/8633575#8633575 + nerdctlOpt, err := option.New([]string{subject, "shell", vmName, "sudo", "-E", "nerdctl"}, option.Env(passThroughEnvVars)) if err != nil { t.Fatalf("failed to initialize a testing option: %v", err) } diff --git a/e2e/go.mod b/e2e/go.mod index e2ee319..2dbc4a5 100644 --- a/e2e/go.mod +++ b/e2e/go.mod @@ -5,7 +5,7 @@ go 1.22 require ( github.com/onsi/ginkgo/v2 v2.20.2 github.com/onsi/gomega v1.36.1 - github.com/runfinch/common-tests v0.7.22 + github.com/runfinch/common-tests v0.8.0 ) require ( diff --git a/e2e/go.sum b/e2e/go.sum index c7213c6..8addba7 100644 --- a/e2e/go.sum +++ b/e2e/go.sum @@ -14,8 +14,8 @@ github.com/onsi/gomega v1.36.1 h1:bJDPBO7ibjxcbHMgSCoo4Yj18UWbKDlLwX1x9sybDcw= github.com/onsi/gomega v1.36.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/runfinch/common-tests v0.7.22 h1:LnQiSrQmmYUIc600FVsMk265kPnzCeFw94DbbCVDOwo= -github.com/runfinch/common-tests v0.7.22/go.mod h1:zzjBhz8poviFC3/kOmmJsUdiKGxMRoAh/AIUyy3YqGQ= +github.com/runfinch/common-tests v0.8.0 h1:ctMpeHjUemEQaJ28EZ0oFsAxYopmhkslqQzd8pAoFYE= +github.com/runfinch/common-tests v0.8.0/go.mod h1:Kf6ofmyppurRrGGaZVj43J++fDJ2wQ2lFRg8J6YYbwM= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=