mirror of https://github.com/docker/cli.git
add ability to override ints in compose files with 0
Signed-off-by: Marco Spiess <marco.spiess@hotmail.de>
This commit is contained in:
parent
ed525aa322
commit
68330e099a
|
@ -61,6 +61,7 @@ func mergeServices(base, override []types.ServiceConfig) ([]types.ServiceConfig,
|
|||
reflect.TypeOf([]types.ServiceVolumeConfig{}): mergeSlice(toServiceVolumeConfigsMap, toServiceVolumeConfigsSlice),
|
||||
reflect.TypeOf(types.ShellCommand{}): mergeShellCommand,
|
||||
reflect.TypeOf(&types.ServiceNetworkConfig{}): mergeServiceNetworkConfig,
|
||||
reflect.PointerTo(reflect.TypeOf(uint64(1))): mergeUint64,
|
||||
},
|
||||
}
|
||||
for name, overrideService := range overrideServices {
|
||||
|
@ -259,6 +260,14 @@ func mergeServiceNetworkConfig(dst, src reflect.Value) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func mergeUint64(dst, src reflect.Value) error {
|
||||
if !src.IsNil() {
|
||||
dst.Elem().Set(src.Elem())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getLoggingDriver(v reflect.Value) string {
|
||||
return v.FieldByName("Driver").String()
|
||||
}
|
||||
|
|
|
@ -1237,3 +1237,60 @@ func TestMergeServiceNetworkConfig(t *testing.T) {
|
|||
},
|
||||
)
|
||||
}
|
||||
|
||||
// issue #3293
|
||||
func TestMergeServiceOverrideReplicasZero(t *testing.T) {
|
||||
base := types.ServiceConfig{
|
||||
Name: "someService",
|
||||
Deploy: types.DeployConfig{
|
||||
Replicas: uint64Ptr(3),
|
||||
},
|
||||
}
|
||||
override := types.ServiceConfig{
|
||||
Name: "someService",
|
||||
Deploy: types.DeployConfig{
|
||||
Replicas: uint64Ptr(0),
|
||||
},
|
||||
}
|
||||
services, err := mergeServices([]types.ServiceConfig{base}, []types.ServiceConfig{override})
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, len(services), 1)
|
||||
actual := services[0]
|
||||
assert.DeepEqual(
|
||||
t,
|
||||
actual,
|
||||
types.ServiceConfig{
|
||||
Name: "someService",
|
||||
Deploy: types.DeployConfig{
|
||||
Replicas: uint64Ptr(0),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestMergeServiceOverrideReplicasNotNil(t *testing.T) {
|
||||
base := types.ServiceConfig{
|
||||
Name: "someService",
|
||||
Deploy: types.DeployConfig{
|
||||
Replicas: uint64Ptr(3),
|
||||
},
|
||||
}
|
||||
override := types.ServiceConfig{
|
||||
Name: "someService",
|
||||
Deploy: types.DeployConfig{},
|
||||
}
|
||||
services, err := mergeServices([]types.ServiceConfig{base}, []types.ServiceConfig{override})
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, len(services), 1)
|
||||
actual := services[0]
|
||||
assert.DeepEqual(
|
||||
t,
|
||||
actual,
|
||||
types.ServiceConfig{
|
||||
Name: "someService",
|
||||
Deploy: types.DeployConfig{
|
||||
Replicas: uint64Ptr(3),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue