| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package merge3_test |
| 5 |
|
| 6 |
import ( |
| 7 |
"strings" |
| 8 |
"testing" |
| 9 |
|
| 10 |
"github.com/stretchr/testify/assert" |
| 11 |
. "sigs.k8s.io/kustomize/kyaml/yaml/merge3" |
| 12 |
) |
| 13 |
|
| 14 |
var testCases = [][]testCase{scalarTestCases, listTestCases, mapTestCases, elementTestCases, kustomizationTestCases} |
| 15 |
|
| 16 |
func TestMerge(t *testing.T) { |
| 17 |
for i := range testCases { |
| 18 |
for j := range testCases[i] { |
| 19 |
tc := testCases[i][j] |
| 20 |
t.Run(tc.description, func(t *testing.T) { |
| 21 |
actual, err := MergeStrings(tc.local, tc.origin, tc.update, tc.infer) |
| 22 |
if tc.err == nil { |
| 23 |
if !assert.NoError(t, err, tc.description) { |
| 24 |
t.FailNow() |
| 25 |
} |
| 26 |
if !assert.Equal(t, |
| 27 |
strings.TrimSpace(tc.expected), strings.TrimSpace(actual), tc.description) { |
| 28 |
t.FailNow() |
| 29 |
} |
| 30 |
} else { |
| 31 |
if !assert.Errorf(t, err, tc.description) { |
| 32 |
t.FailNow() |
| 33 |
} |
| 34 |
if !assert.Contains(t, tc.err.Error(), err.Error()) { |
| 35 |
t.FailNow() |
| 36 |
} |
| 37 |
} |
| 38 |
}) |
| 39 |
} |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
type testCase struct { |
| 44 |
description string |
| 45 |
origin string |
| 46 |
update string |
| 47 |
local string |
| 48 |
expected string |
| 49 |
err error |
| 50 |
infer bool |
| 51 |
} |