mapping_test.go
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package utils
import (
"github.com/tiptok/gocomm/common"
"testing"
)
func TestLoadCustomField(t *testing.T) {
type User struct {
Name string
Id int
}
v := []struct {
Name string
Id int
}{{Name: "c1", Id: 1}, {Name: "c2", Id: 2}, {Name: "c3", Id: 3}}
ret := LoadCustomField(&v, "Name")
t.Log(common.JsonAssertString(ret))
v2 := struct {
Name string
Id int
}{Name: "c1", Id: 1}
ret2 := LoadCustomField(v2, "Name", "Id")
t.Log(common.JsonAssertString(ret2))
v3 := []*User{&User{Name: "c1", Id: 1}, &User{Name: "c2", Id: 2}, &User{Name: "c3", Id: 3}}
ret3 := LoadCustomField(&v3, "Name", "Name2")
t.Log(common.JsonAssertString(ret3))
}
func TestAppendCustomField(t *testing.T) {
customMap := map[string]interface{}{"1": "h", "2": "e"}
t.Log(customMap)
customeFiles := map[string]interface{}{
"Value": map[string]interface{}{"a": "a", "b": "b"},
"Value2": "cc",
"Value3": 9999,
}
t.Log(AppendCustomField(customMap, customeFiles))
t.Log(AppendCustomField(struct {
Name string `json:"name"`
Age int64 `json:"age"`
}{Name: "ccc", Age: 20}, customeFiles))
}