Skip to content

Commit

Permalink
Apply transformStringOrList to services.*.label_file
Browse files Browse the repository at this point in the history
Signed-off-by: Vigilans <[email protected]>
  • Loading branch information
Vigilans authored and ndeloof committed Jan 6, 2025
1 parent 3f71fb0 commit 7f822e3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
49 changes: 49 additions & 0 deletions loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,55 @@ networks:
assertEqual(t, expected, config)
}

func TestLoadWithLabelFile(t *testing.T) {
workingDir, err := os.Getwd()
assert.NilError(t, err)
config, err := loadYAML(`
name: load-label-file
services:
service_1:
label_file: ./example1.label
service_2:
label_file:
- ./example2.label
`)
assert.NilError(t, err)

expected := &types.Project{
Name: "load-label-file",
Environment: types.Mapping{"COMPOSE_PROJECT_NAME": "load-label-file"},
WorkingDir: workingDir,
Services: types.Services{
"service_1": {
Name: "service_1",
Environment: types.MappingWithEquals{},
Labels: types.Labels{
"BAR": "bar_from_label_file",
"BAZ": "baz_from_label_file",
"FOO": "foo_from_label_file",
"LABEL.WITH.DOT": "ok",
"LABEL_WITH_UNDERSCORE": "ok",
},
LabelFiles: []string{
filepath.Join(workingDir, "example1.label"),
},
},
"service_2": {
Name: "service_2",
Environment: types.MappingWithEquals{},
Labels: types.Labels{
"BAR": "bar_from_label_file_2",
"QUX": "quz_from_label_file_2",
},
LabelFiles: []string{
filepath.Join(workingDir, "example2.label"),
},
},
},
}
assertEqual(t, config, expected)
}

func TestUnsupportedProperties(t *testing.T) {
dict := `
name: test
Expand Down
1 change: 1 addition & 0 deletions transform/canonical.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func init() {
transformers["services.*.build.additional_contexts"] = transformKeyValue
transformers["services.*.depends_on"] = transformDependsOn
transformers["services.*.env_file"] = transformEnvFile
transformers["services.*.label_file"] = transformStringOrList
transformers["services.*.extends"] = transformExtends
transformers["services.*.networks"] = transformServiceNetworks
transformers["services.*.volumes.*"] = transformVolumeMount
Expand Down

0 comments on commit 7f822e3

Please sign in to comment.