Add unit test for pkg/charts/charts.go (#5565)

Add tests for MergeMap

Signed-off-by: Hu Shuai <hus.fnst@cn.fujitsu.com>
This commit is contained in:
Hu Shuai 2021-01-20 22:55:01 +08:00 committed by GitHub
parent 3b755e5c1d
commit 08439f1f6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 37 additions and 0 deletions

37
pkg/charts/charts_test.go Normal file
View File

@ -0,0 +1,37 @@
package charts
import (
"reflect"
"testing"
)
func TestMergeMaps(t *testing.T) {
for _, tc := range []struct {
a, b, expected map[string]interface{}
}{
{
a: map[string]interface{}{"aaa": "foo"},
b: map[string]interface{}{"bbb": "bar"},
expected: map[string]interface{}{"aaa": "foo", "bbb": "bar"},
},
{
a: map[string]interface{}{"aaa": "foo"},
b: map[string]interface{}{"aaa": "bar", "bbb": "bar"},
expected: map[string]interface{}{"aaa": "bar", "bbb": "bar"},
},
{
a: map[string]interface{}{"aaa": "foo", "bbb": map[string]interface{}{"aaa": "foo"}},
b: map[string]interface{}{"aaa": "bar", "bbb": map[string]interface{}{"aaa": "bar"}},
expected: map[string]interface{}{"aaa": "bar", "bbb": map[string]interface{}{"aaa": "bar"}},
},
{
a: map[string]interface{}{"aaa": "foo", "bbb": map[string]interface{}{"aaa": "foo"}},
b: map[string]interface{}{"aaa": "foo", "bbb": map[string]interface{}{"aaa": "bar", "ccc": "foo"}},
expected: map[string]interface{}{"aaa": "foo", "bbb": map[string]interface{}{"aaa": "bar", "ccc": "foo"}},
},
} {
if !reflect.DeepEqual(MergeMaps(tc.a, tc.b), tc.expected) {
t.Errorf("expected: %v, got: %v", tc.expected, MergeMaps(tc.a, tc.b))
}
}
}