Add merge to ShellCommand properties in config

Signed-off-by: Stoica-Marcu Floris-Andrei <floris.sm@gmail.com>
This commit is contained in:
Stoica-Marcu Floris-Andrei 2020-09-23 03:33:30 +03:00 committed by Sebastiaan van Stijn
parent fbea85d472
commit cff702d889
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 57 additions and 3 deletions

View File

@ -59,6 +59,7 @@ func mergeServices(base, override []types.ServiceConfig) ([]types.ServiceConfig,
reflect.TypeOf([]types.ServiceConfigObjConfig{}): mergeSlice(toServiceConfigObjConfigsMap, toSServiceConfigObjConfigsSlice), reflect.TypeOf([]types.ServiceConfigObjConfig{}): mergeSlice(toServiceConfigObjConfigsMap, toSServiceConfigObjConfigsSlice),
reflect.TypeOf(&types.UlimitsConfig{}): mergeUlimitsConfig, reflect.TypeOf(&types.UlimitsConfig{}): mergeUlimitsConfig,
reflect.TypeOf([]types.ServiceVolumeConfig{}): mergeSlice(toServiceVolumeConfigsMap, toServiceVolumeConfigsSlice), reflect.TypeOf([]types.ServiceVolumeConfig{}): mergeSlice(toServiceVolumeConfigsMap, toServiceVolumeConfigsSlice),
reflect.TypeOf(types.ShellCommand{}): mergeShellCommand,
reflect.TypeOf(&types.ServiceNetworkConfig{}): mergeServiceNetworkConfig, reflect.TypeOf(&types.ServiceNetworkConfig{}): mergeServiceNetworkConfig,
}, },
} }
@ -235,9 +236,9 @@ func mergeUlimitsConfig(dst, src reflect.Value) error {
} }
//nolint: unparam //nolint: unparam
func mergeServiceVolumeConfig(dst, src reflect.Value) error { func mergeShellCommand(dst, src reflect.Value) error {
if dst.Elem().FieldByName("target").String() == src.Elem().FieldByName("target").String() { if src.Len() != 0 {
dst.Set(src.Elem()) dst.Set(src)
} }
return nil return nil
} }

View File

@ -1017,6 +1017,59 @@ func TestLoadMultipleNetworks(t *testing.T) {
}, config) }, config)
} }
func TestLoadMultipleServiceCommands(t *testing.T) {
base := map[string]interface{}{
"version": "3.7",
"services": map[string]interface{}{
"foo": map[string]interface{}{
"image": "baz",
"command": "foo bar",
},
},
"volumes": map[string]interface{}{},
"networks": map[string]interface{}{},
"secrets": map[string]interface{}{},
"configs": map[string]interface{}{},
}
override := map[string]interface{}{
"version": "3.7",
"services": map[string]interface{}{
"foo": map[string]interface{}{
"image": "baz",
"command": "foo baz",
},
},
"volumes": map[string]interface{}{},
"networks": map[string]interface{}{},
"secrets": map[string]interface{}{},
"configs": map[string]interface{}{},
}
configDetails := types.ConfigDetails{
ConfigFiles: []types.ConfigFile{
{Filename: "base.yml", Config: base},
{Filename: "override.yml", Config: override},
},
}
config, err := Load(configDetails)
assert.NilError(t, err)
assert.DeepEqual(t, &types.Config{
Filename: "base.yml",
Version: "3.7",
Services: []types.ServiceConfig{
{
Name: "foo",
Image: "baz",
Command: types.ShellCommand{"foo", "baz"},
Environment: types.MappingWithEquals{},
},
},
Volumes: map[string]types.VolumeConfig{},
Secrets: map[string]types.SecretConfig{},
Configs: map[string]types.ConfigObjConfig{},
Networks: map[string]types.NetworkConfig{},
}, config)
}
func TestLoadMultipleServiceVolumes(t *testing.T) { func TestLoadMultipleServiceVolumes(t *testing.T) {
base := map[string]interface{}{ base := map[string]interface{}{
"version": "3.7", "version": "3.7",