diff --git a/pkg/loader/compose/compose.go b/pkg/loader/compose/compose.go index 4e17237f..cb5be6f4 100644 --- a/pkg/loader/compose/compose.go +++ b/pkg/loader/compose/compose.go @@ -698,6 +698,7 @@ func parseEnvironment(composeServiceConfig *types.ServiceConfig, serviceConfig * func parseEnvFiles(composeServiceConfig *types.ServiceConfig, serviceConfig *kobject.ServiceConfig) { for _, value := range composeServiceConfig.EnvFiles { serviceConfig.EnvFile = append(serviceConfig.EnvFile, value.Path) + // value.Required is ignored } } diff --git a/pkg/loader/compose/compose_test.go b/pkg/loader/compose/compose_test.go index babe48cf..af9dfa5a 100644 --- a/pkg/loader/compose/compose_test.go +++ b/pkg/loader/compose/compose_test.go @@ -429,6 +429,52 @@ func TestLoadEnvVar(t *testing.T) { } } +func TestParseEnvFiles(t *testing.T) { + tests := []struct { + service types.ServiceConfig + want []string + }{ + {service: types.ServiceConfig{ + Name: "baz", + Image: "foo/baz", + EnvFiles: []types.EnvFile{ + { + Path: "", + Required: false, + }, + { + Path: "foo", + Required: false, + }, + { + Path: "bar", + Required: true, + }, + }, + }, + want: []string{"", "foo", "bar"}, + }, + { + service: types.ServiceConfig{ + Name: "baz", + Image: "foo/baz", + EnvFiles: []types.EnvFile{}, + }, + want: []string{}, + }, + } + + for _, tt := range tests { + sc := kobject.ServiceConfig{ + EnvFile: []string{}, + } + parseEnvFiles(&tt.service, &sc) + if !reflect.DeepEqual(sc.EnvFile, tt.want) { + t.Errorf("Expected %q, got %q", tt.want, sc.EnvFile) + } + } +} + // TestUnsupportedKeys test checkUnsupportedKey function with various // docker-compose projects func TestUnsupportedKeys(t *testing.T) {