-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparser_ptr_test.go
116 lines (107 loc) · 2.55 KB
/
parser_ptr_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package envconf_test
import (
"testing"
"github.com/antonmashko/envconf"
)
func TestStringPointer_InitFromDefault_Ok(t *testing.T) {
data := struct {
Field *string `default:"test"`
}{}
if err := envconf.Parse(&data); err != nil {
t.Fatal(err)
}
if data.Field == nil || *data.Field != "test" {
t.Fatalf("incorrect value. expected=test actual=%s", *data.Field)
}
}
func TestStructPointer_WithFieldFromDefault_Ok(t *testing.T) {
data := struct {
Inner *struct {
Field string `default:"test"`
}
}{}
if err := envconf.Parse(&data); err != nil {
t.Fatal(err)
}
if data.Inner == nil || (*data.Inner).Field != "test" {
t.Fatalf("incorrect value. expected=test actual=%v", data.Inner)
}
}
func TestStringPointer_MultiplePointersFromDefault_Ok(t *testing.T) {
data := struct {
Field ***string `default:"test"`
}{}
if err := envconf.Parse(&data); err != nil {
t.Fatal(err)
}
if data.Field == nil || ***data.Field != "test" {
t.Fatalf("incorrect value. expected=test actual=%s", ***data.Field)
}
}
func TestStructPointer_MultiplePointer_Ok(t *testing.T) {
data := struct {
Inner ***struct {
Field string `default:"test"`
}
}{}
if err := envconf.Parse(&data); err != nil {
t.Fatal(err)
}
if data.Inner == nil || (***data.Inner).Field != "test" {
t.Fatalf("incorrect value. expected=test actual=%v", data.Inner)
}
}
func TestStringPoint_WithoutValue_Ok(t *testing.T) {
data := struct {
Field *string
}{}
if err := envconf.Parse(&data); err != nil {
t.Fatal(err)
}
if data.Field != nil {
t.Fatal("field not nil")
}
}
func TestStructPoint_WithoutValue_Ok(t *testing.T) {
data := struct {
Inner *struct {
Field string
}
}{}
if err := envconf.Parse(&data); err != nil {
t.Fatal(err)
}
if data.Inner != nil {
t.Fatalf("incorrect value. expected=test actual=%v", data.Inner)
}
}
func TestStructPoint_FewInnerOneWithValue_Ok(t *testing.T) {
data := struct {
Inner1 *struct {
Field string
}
Inner2 struct {
Inner21 **struct {
Field string
}
Field string
}
Inner3 *struct {
Inner31 *struct {
Field string `default:"test"`
}
}
}{}
if err := envconf.Parse(&data); err != nil {
t.Fatal(err)
}
if data.Inner1 != nil {
t.Fatalf("incorrect value Inner1. expected=nil actual=%v", data.Inner1)
}
if data.Inner2.Inner21 != nil {
t.Fatalf("incorrect value Inner2. expected=nil actual=%v", data.Inner2.Inner21)
}
if data.Inner3 == nil || data.Inner3.Inner31 == nil || data.Inner3.Inner31.Field != "test" {
t.Fatalf("incorrect value Inner3. expected=not_nil actual=%#v", data.Inner3)
}
}