From e153dd1d34b6e7c8e84ca315a76310982f19cf47 Mon Sep 17 00:00:00 2001 From: Vigilans Date: Sun, 22 Dec 2024 13:59:31 +0800 Subject: [PATCH] Apply `transformStringOrList` to `services.*.label_file` Signed-off-by: Vigilans --- loader/loader_test.go | 49 ++++++++++++++++++++++++++++++++++++++++++ transform/canonical.go | 1 + 2 files changed, 50 insertions(+) diff --git a/loader/loader_test.go b/loader/loader_test.go index 8f062c00..125bf29f 100644 --- a/loader/loader_test.go +++ b/loader/loader_test.go @@ -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 diff --git a/transform/canonical.go b/transform/canonical.go index ff5bb37d..2ace976c 100644 --- a/transform/canonical.go +++ b/transform/canonical.go @@ -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