Skip to content

Commit

Permalink
add tests for dynamic converter
Browse files Browse the repository at this point in the history
  • Loading branch information
Di Weng committed Feb 23, 2022
1 parent d2db312 commit f9afcb6
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions kusto/data/value/dynamic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ func TestDynamicConverter(t *testing.T) {
{"name": "B", "id": 2},
},
},
{
Desc: "convert to []map[string]struct",
Value: value.Dynamic{Value: []byte(`[{"group1":{"name":"A","id":1}},{"group2":{"name":"B","id":2}}]`), Valid: true},
Target: reflect.ValueOf(&[]map[string]TestStruct{}),
Want: []map[string]TestStruct{
{"group1": {Name: "A", ID: 1}},
{"group2": {Name: "B", ID: 2}},
},
},
{
Desc: "convert to struct",
Value: value.Dynamic{Value: []byte(`{"name":"A","id":1}`), Valid: true},
Expand All @@ -84,6 +93,17 @@ func TestDynamicConverter(t *testing.T) {
"id": 1,
},
},
{
Desc: "convert to map[string]struct",
Value: value.Dynamic{Value: []byte(`{"group1": {"name":"A","id":1}}`), Valid: true},
Target: reflect.ValueOf(&map[string]TestStruct{}),
Want: map[string]TestStruct{
"group1": {
Name: "A",
ID: 1,
},
},
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit f9afcb6

Please # to comment.