forked from free5gc/openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_test.go
47 lines (40 loc) · 854 Bytes
/
convert_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
package openapi
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type Struct struct {
A []string
S string
N int
M map[int]string
DT *time.Time
}
func TestConvert(t *testing.T) {
from := map[string]interface{}{
"A": []string{"Hello", "World"},
"S": "This is a string",
"N": 10,
"M": map[int]interface{}{
1: "one",
2: "two",
3: "three",
},
"DT": "2020-05-01T12:04:05+08:00",
}
var to Struct
err := Convert(from, &to)
assert.Nil(t, err, "convert failed")
// check data is correct
assert.Equal(t, []string{"Hello", "World"}, to.A)
assert.Equal(t, "This is a string", to.S)
assert.Equal(t, 10, to.N)
assert.Equal(t, map[int]string{
1: "one",
2: "two",
3: "three",
}, to.M)
expectTime, err := time.Parse(time.RFC3339, "2020-05-01T12:04:05+08:00")
assert.Equal(t, expectTime, *to.DT)
}