...
1
2
3
4 package merge2_test
5
6 import (
7 "bytes"
8 "strings"
9 "testing"
10
11 "github.com/stretchr/testify/assert"
12 "sigs.k8s.io/kustomize/kyaml/kio/filters"
13 "sigs.k8s.io/kustomize/kyaml/yaml"
14 . "sigs.k8s.io/kustomize/kyaml/yaml/merge2"
15 )
16
17 var testCases = [][]testCase{scalarTestCases, listTestCases, elementTestCases, mapTestCases}
18
19 func TestMerge(t *testing.T) {
20 for i := range testCases {
21 for j := range testCases[i] {
22 tc := testCases[i][j]
23 t.Run(tc.description, func(t *testing.T) {
24 actual, err := MergeStrings(tc.source, tc.dest, tc.infer, tc.mergeOptions)
25 if !assert.NoError(t, err, tc.description) {
26 t.FailNow()
27 }
28 e, err := filters.FormatInput(bytes.NewBufferString(tc.expected))
29 if !assert.NoError(t, err) {
30 t.FailNow()
31 }
32 estr := strings.TrimSpace(e.String())
33 a, err := filters.FormatInput(bytes.NewBufferString(actual))
34 if !assert.NoError(t, err) {
35 t.FailNow()
36 }
37 astr := strings.TrimSpace(a.String())
38 if !assert.Equal(t, estr, astr, tc.description) {
39 t.FailNow()
40 }
41 })
42 }
43 }
44 }
45
46 type testCase struct {
47 description string
48 source string
49 dest string
50 expected string
51 infer bool
52 mergeOptions yaml.MergeOptions
53 }
54
View as plain text