mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Improve TestMergoSemantics test
This commit is contained in:
parent
a1f6d24962
commit
194c471c9c
@ -29,22 +29,47 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestMergoSemantics(t *testing.T) {
|
func TestMergoSemantics(t *testing.T) {
|
||||||
|
type U struct {
|
||||||
|
A string
|
||||||
|
B int64
|
||||||
|
}
|
||||||
type T struct {
|
type T struct {
|
||||||
X string
|
X string
|
||||||
|
Y int64
|
||||||
|
U U
|
||||||
}
|
}
|
||||||
dst := T{X: "one"}
|
var testData = []struct {
|
||||||
src := T{X: "two"}
|
dst T
|
||||||
mergo.MergeWithOverwrite(&dst, &src)
|
src T
|
||||||
if dst.X != "two" {
|
expected T
|
||||||
// The mergo library has previously changed in a an incompatible way.
|
}{
|
||||||
// example:
|
{
|
||||||
//
|
dst: T{X: "one"},
|
||||||
// https://github.com/imdario/mergo/commit/d304790b2ed594794496464fadd89d2bb266600a
|
src: T{X: "two"},
|
||||||
//
|
expected: T{X: "two"},
|
||||||
// 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.
|
dst: T{X: "one", Y: 5, U: U{A: "four", B: 6}},
|
||||||
t.Errorf("mergo.MergeWithOverwrite did not provide expected output")
|
src: T{X: "two", U: U{A: "three", B: 4}},
|
||||||
|
expected: T{X: "two", Y: 5, U: U{A: "three", B: 4}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, data := range testData {
|
||||||
|
err := mergo.MergeWithOverwrite(&data.dst, &data.src)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("error while merging: %s", err)
|
||||||
|
}
|
||||||
|
if data.dst != data.expected {
|
||||||
|
// The mergo library has previously changed in a an incompatible way.
|
||||||
|
// example:
|
||||||
|
//
|
||||||
|
// https://github.com/imdario/mergo/commit/d304790b2ed594794496464fadd89d2bb266600a
|
||||||
|
//
|
||||||
|
// 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: %+v doesn't match %+v", data.dst, data.expected)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user