Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump mergo v0.3.8 #2277

Merged
merged 2 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions cli/compose/loader/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func mergeServices(base, override []types.ServiceConfig) ([]types.ServiceConfig,
reflect.TypeOf([]types.ServicePortConfig{}): mergeSlice(toServicePortConfigsMap, toServicePortConfigsSlice),
reflect.TypeOf([]types.ServiceSecretConfig{}): mergeSlice(toServiceSecretConfigsMap, toServiceSecretConfigsSlice),
reflect.TypeOf([]types.ServiceConfigObjConfig{}): mergeSlice(toServiceConfigObjConfigsMap, toSServiceConfigObjConfigsSlice),
reflect.TypeOf(&types.UlimitsConfig{}): mergeUlimitsConfig,
reflect.TypeOf(&types.ServiceNetworkConfig{}): mergeServiceNetworkConfig,
},
}
for name, overrideService := range overrideServices {
Expand Down Expand Up @@ -201,6 +203,28 @@ func mergeLoggingConfig(dst, src reflect.Value) error {
return nil
}

//nolint: unparam
func mergeUlimitsConfig(dst, src reflect.Value) error {
if src.Interface() != reflect.Zero(reflect.TypeOf(src.Interface())).Interface() {
dst.Elem().Set(src.Elem())
}
return nil
}

//nolint: unparam
func mergeServiceNetworkConfig(dst, src reflect.Value) error {
if src.Interface() != reflect.Zero(reflect.TypeOf(src.Interface())).Interface() {
dst.Elem().FieldByName("Aliases").Set(src.Elem().FieldByName("Aliases"))
if ipv4 := src.Elem().FieldByName("Ipv4Address").Interface().(string); ipv4 != "" {
dst.Elem().FieldByName("Ipv4Address").SetString(ipv4)
}
if ipv6 := src.Elem().FieldByName("Ipv6Address").Interface().(string); ipv6 != "" {
dst.Elem().FieldByName("Ipv6Address").SetString(ipv6)
}
}
return nil
}

func getLoggingDriver(v reflect.Value) string {
return v.FieldByName("Driver").String()
}
Expand Down
93 changes: 93 additions & 0 deletions cli/compose/loader/merge_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package loader

import (
"reflect"
"testing"

"github.com/docker/cli/cli/compose/types"
"github.com/imdario/mergo"
"gotest.tools/assert"
)

Expand Down Expand Up @@ -1014,3 +1016,94 @@ func TestLoadMultipleNetworks(t *testing.T) {
Configs: map[string]types.ConfigObjConfig{},
}, config)
}

func TestMergeUlimitsConfig(t *testing.T) {
specials := &specials{
m: map[reflect.Type]func(dst, src reflect.Value) error{
reflect.TypeOf(&types.UlimitsConfig{}): mergeUlimitsConfig,
},
}
base := map[string]*types.UlimitsConfig{
"override-single": &types.UlimitsConfig{Single: 100},
"override-single-with-soft-hard": &types.UlimitsConfig{Single: 200},
"override-soft-hard": &types.UlimitsConfig{Soft: 300, Hard: 301},
"override-soft-hard-with-single": &types.UlimitsConfig{Soft: 400, Hard: 401},
"dont-override": &types.UlimitsConfig{Single: 500},
}
override := map[string]*types.UlimitsConfig{
"override-single": &types.UlimitsConfig{Single: 110},
"override-single-with-soft-hard": &types.UlimitsConfig{Soft: 210, Hard: 211},
"override-soft-hard": &types.UlimitsConfig{Soft: 310, Hard: 311},
"override-soft-hard-with-single": &types.UlimitsConfig{Single: 410},
"add": &types.UlimitsConfig{Single: 610},
}
err := mergo.Merge(&base, &override, mergo.WithOverride, mergo.WithTransformers(specials))
assert.NilError(t, err)
assert.DeepEqual(
t,
base,
map[string]*types.UlimitsConfig{
"override-single": &types.UlimitsConfig{Single: 110},
"override-single-with-soft-hard": &types.UlimitsConfig{Soft: 210, Hard: 211},
"override-soft-hard": &types.UlimitsConfig{Soft: 310, Hard: 311},
"override-soft-hard-with-single": &types.UlimitsConfig{Single: 410},
"dont-override": &types.UlimitsConfig{Single: 500},
"add": &types.UlimitsConfig{Single: 610},
},
)
}

func TestMergeServiceNetworkConfig(t *testing.T) {
specials := &specials{
m: map[reflect.Type]func(dst, src reflect.Value) error{
reflect.TypeOf(&types.ServiceNetworkConfig{}): mergeServiceNetworkConfig,
},
}
base := map[string]*types.ServiceNetworkConfig{
"override-aliases": &types.ServiceNetworkConfig{
Aliases: []string{"100", "101"},
Ipv4Address: "127.0.0.1",
Ipv6Address: "0:0:0:0:0:0:0:1",
},
"dont-override": &types.ServiceNetworkConfig{
Aliases: []string{"200", "201"},
Ipv4Address: "127.0.0.2",
Ipv6Address: "0:0:0:0:0:0:0:2",
},
}
override := map[string]*types.ServiceNetworkConfig{
"override-aliases": &types.ServiceNetworkConfig{
Aliases: []string{"110", "111"},
Ipv4Address: "127.0.1.1",
Ipv6Address: "0:0:0:0:0:0:1:1",
},
"add": &types.ServiceNetworkConfig{
Aliases: []string{"310", "311"},
Ipv4Address: "127.0.3.1",
Ipv6Address: "0:0:0:0:0:0:3:1",
},
}
err := mergo.Merge(&base, &override, mergo.WithOverride, mergo.WithTransformers(specials))
assert.NilError(t, err)
assert.DeepEqual(
t,
base,
map[string]*types.ServiceNetworkConfig{
"override-aliases": &types.ServiceNetworkConfig{
Aliases: []string{"110", "111"},
Ipv4Address: "127.0.1.1",
Ipv6Address: "0:0:0:0:0:0:1:1",
},
"dont-override": &types.ServiceNetworkConfig{
Aliases: []string{"200", "201"},
Ipv4Address: "127.0.0.2",
Ipv6Address: "0:0:0:0:0:0:0:2",
},
"add": &types.ServiceNetworkConfig{
Aliases: []string{"310", "311"},
Ipv4Address: "127.0.3.1",
Ipv6Address: "0:0:0:0:0:0:3:1",
},
},
)
}
2 changes: 1 addition & 1 deletion vendor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ github.com/gorilla/mux 00bdffe0f3c77e27d2cf6f5c7023
github.com/grpc-ecosystem/grpc-gateway 1a03ca3bad1e1ebadaedd3abb76bc58d4ac8143b
github.com/grpc-ecosystem/grpc-opentracing 8e809c8a86450a29b90dcc9efbf062d0fe6d9746
github.com/hashicorp/golang-lru 7f827b33c0f158ec5dfbba01bb0b14a4541fd81d # v0.5.3
github.com/imdario/mergo 7c29201646fa3de8506f701213473dd407f19646 # v0.3.7
github.com/imdario/mergo 1afb36080aec31e0d1528973ebe6721b191b0369 # v0.3.8
github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 # v1.0.0
github.com/jaguilar/vt100 ad4c4a5743050fb7f88ce968dca9422f72a0e3f2 git://github.com/tonistiigi/vt100.git
github.com/json-iterator/go 0ff49de124c6f76f8494e194af75bde0f1a49a29 # 1.1.6
Expand Down
50 changes: 39 additions & 11 deletions vendor/github.com/imdario/mergo/merge.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.