Move from mergo.Merge to mergo.MergeWithOverwrite

Kubernetes-commit: a1f6d24962f2b9e6002bcc721e1b48d1008d6cbf
This commit is contained in:
Christoph Blecker
2018-07-04 12:52:01 -07:00
committed by Kubernetes Publisher
parent e88f376842
commit 44530d33a7
3 changed files with 24 additions and 26 deletions

View File

@@ -28,21 +28,23 @@ import (
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
)
func TestOldMergoLib(t *testing.T) {
func TestMergoSemantics(t *testing.T) {
type T struct {
X string
}
dst := T{X: "one"}
src := T{X: "two"}
mergo.Merge(&dst, &src)
mergo.MergeWithOverwrite(&dst, &src)
if dst.X != "two" {
// mergo.Merge changed in an incompatible way with
// The mergo library has previously changed in a an incompatible way.
// example:
//
// https://github.com/imdario/mergo/commit/d304790b2ed594794496464fadd89d2bb266600a
//
// We have to stay with the old version which still does eager
// copying from src to dst in structs.
t.Errorf("mergo.Merge library found with incompatible, new behavior")
// This test verifies that the semantics of the merge are what we expect.
// If they are not, the mergo library may have been updated and broken
// unexpectedly.
t.Errorf("mergo.MergeWithOverwrite did not provide expected output")
}
}