-
Notifications
You must be signed in to change notification settings - Fork 1
/
struct_test.go
65 lines (54 loc) · 1.65 KB
/
struct_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
package gotools
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type _Example struct {
Name string `json:"name"`
Age uint64 `json:"age"`
Num *uint `json:"number"`
de string `json:"de"`
Labels map[string]interface{} `json:"labels"`
CreatedAt time.Time `json:"created_at"`
d _Example2 `json:"d"`
*_Example2
*Example2
}
type _Example2 struct {
Values string `json:"values"`
Value2 string `json:"value_2"`
}
type Example2 struct {
Values string `json:"upper_values"`
Value2 string `json:"upper_value_2"`
}
var example _Example = _Example{
d: _Example2{
"d1",
"d2",
},
_Example2: &_Example2{
"ptr_private_1",
"ptr_private_2",
},
Example2: &Example2{
"ptr_1",
"ptr_2",
},
}
func TestStructTagAllFields(t *testing.T) {
result := []string{"name", "age", "number", "de", "labels", "created_at", "d", "values", "value_2", "upper_values", "upper_value_2"}
tags, _ := StructTagAllFields(example, "json")
assert.Equal(t, result, tags, "the should be equal")
}
func TestStructTagExportedFields(t *testing.T) {
result := []string{"name", "age", "number", "labels", "created_at", "upper_values", "upper_value_2"}
tags, _ := StructTagExportedFields(example, "json")
assert.Equal(t, result, tags, "the should be equal")
}
func TestStructTagExportedFieldValues(t *testing.T) {
result := []interface{}{example.Name, example.Age, uint(0), example.Labels, example.CreatedAt, example.Example2.Values, example.Example2.Value2}
tags, _ := StructTagExportedFieldValues(example, "json")
assert.Equal(t, result, tags, "the should be equal")
}