-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta_test.go
82 lines (79 loc) · 1.61 KB
/
meta_test.go
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package meta
import (
"reflect"
"testing"
)
func TestMeta_MapTo(t *testing.T) {
type fields struct {
name string
properties map[string]any
}
tests := []struct {
name string
fields fields
input any
wantErr bool
wanted any
}{
{
name: "should map struct",
fields: fields{
name: "Test",
properties: map[string]any{
"StrField": "string",
"IntField": int64(1),
"Int64Field": int64(1),
"Uint64Field": int64(1),
"Int32Field": int64(1),
"Uint32Field": int64(1),
"BoolField1": true,
"BoolField2": false,
"Float32Field": float64(1),
"Float64Field": float64(1),
},
},
input: &MetaStruct{},
wantErr: false,
wanted: &MetaStruct{
StrField: "string",
IntField: 1,
Int64Field: 1,
Uint64Field: 1,
Int32Field: 1,
Uint32Field: 1,
BoolField1: true,
BoolField2: false,
Float32Field: 1,
Float64Field: 1,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := &Meta{
qualifyName: tt.fields.name,
properties: tt.fields.properties,
}
err := m.MapTo(tt.input)
if (err != nil) != tt.wantErr {
t.Errorf("MapStruct() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(tt.input, tt.wanted) {
t.Errorf("MapStruct() = %v, want %v", tt.input, tt.wanted)
}
})
}
}
type MetaStruct struct {
StrField string
IntField int
Int64Field int64
Uint64Field uint64
Int32Field int32
Uint32Field uint32
BoolField1 bool
BoolField2 bool
Float32Field float32
Float64Field float64
}