-
Notifications
You must be signed in to change notification settings - Fork 5
/
convert_test.go
54 lines (46 loc) · 1.04 KB
/
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
48
49
50
51
52
53
54
// Copyright 2019 Communication Service/Software Laboratory, National Chiao Tung University (free5gc.org)
//
// SPDX-License-Identifier: Apache-2.0
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")
if err != nil {
assert.FailNow(t, "failed to parse time")
}
assert.Equal(t, expectTime, *to.DT)
}