Skip to content

Commit

Permalink
testcase for init boolean pointer override
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Nov 30, 2022
1 parent 999ce24 commit b61c59c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
5 changes: 4 additions & 1 deletion loader/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ func mergeServices(base, override []types.ServiceConfig) ([]types.ServiceConfig,
}

func _merge(baseService *types.ServiceConfig, overrideService *types.ServiceConfig) (*types.ServiceConfig, error) {
if err := mergo.Merge(baseService, overrideService, mergo.WithAppendSlice, mergo.WithOverride, mergo.WithTransformers(serviceSpecials)); err != nil {
if err := mergo.Merge(baseService, overrideService,
mergo.WithAppendSlice,
mergo.WithOverride,
mergo.WithTransformers(serviceSpecials)); err != nil {
return nil, err
}
if overrideService.Command != nil {
Expand Down
39 changes: 39 additions & 0 deletions loader/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,45 @@ func TestMergeUlimitsConfig(t *testing.T) {
)
}

func TestInitOverride(t *testing.T) {
var (
bt = true
bf = false
)
cases := []struct {
base *bool
override *bool
expect bool
}{
{
base: &bt,
override: &bf,
expect: false,
},
{
base: nil,
override: &bt,
expect: true,
},
{
base: &bt,
override: nil,
expect: true,
},
}
for _, test := range cases {
base := types.ServiceConfig{
Init: test.base,
}
override := types.ServiceConfig{
Init: test.override,
}
config, err := _merge(&base, &override)
assert.NilError(t, err)
assert.Check(t, *config.Init == test.expect)
}
}

func TestMergeServiceNetworkConfig(t *testing.T) {
specials := &specials{
m: map[reflect.Type]func(dst, src reflect.Value) error{
Expand Down

0 comments on commit b61c59c

Please sign in to comment.