Add tests for parseEnvFiles

This commit is contained in:
Ambrose Chua 2024-03-25 10:34:39 +08:00
parent 5ba743afea
commit f291caa00d
No known key found for this signature in database
GPG Key ID: 36C99AADD44C83D2
2 changed files with 47 additions and 0 deletions

View File

@ -698,6 +698,7 @@ func parseEnvironment(composeServiceConfig *types.ServiceConfig, serviceConfig *
func parseEnvFiles(composeServiceConfig *types.ServiceConfig, serviceConfig *kobject.ServiceConfig) { func parseEnvFiles(composeServiceConfig *types.ServiceConfig, serviceConfig *kobject.ServiceConfig) {
for _, value := range composeServiceConfig.EnvFiles { for _, value := range composeServiceConfig.EnvFiles {
serviceConfig.EnvFile = append(serviceConfig.EnvFile, value.Path) serviceConfig.EnvFile = append(serviceConfig.EnvFile, value.Path)
// value.Required is ignored
} }
} }

View File

@ -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 // TestUnsupportedKeys test checkUnsupportedKey function with various
// docker-compose projects // docker-compose projects
func TestUnsupportedKeys(t *testing.T) { func TestUnsupportedKeys(t *testing.T) {