-
Notifications
You must be signed in to change notification settings - Fork 0
/
envmap_test.go
154 lines (146 loc) · 2.76 KB
/
envmap_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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package envparse
import (
"reflect"
"testing"
)
func TestNewEnvMap(t *testing.T) {
type testDataType struct {
in []string
out envMap
}
testData := []*testDataType{
{
in: nil,
out: map[string]string{},
},
{
in: []string{
"TEST=1",
},
out: map[string]string{
"TEST": "1",
},
},
{
in: []string{
"TEST/1=1",
},
out: map[string]string{
"TEST/1": "1",
},
},
{
in: []string{
"TEST",
},
out: map[string]string{},
},
}
for _, datum := range testData {
out := newEnvMap("", datum.in)
if !reflect.DeepEqual(out, datum.out) {
t.Errorf("expected '%v', but got '%v'", datum.out, out)
}
}
}
func TestEnvMap_Exists(t *testing.T) {
m := envMap{
"TEST": "1",
}
if !m.Exists("TEST") {
t.Errorf("expected TEST exists, but got TEST not exists")
}
if m.Exists("TEST2") {
t.Errorf("expected TEST2 not exists, but got TEST2 exists")
}
if m.Exists("TE") {
t.Errorf("expected TE not exists, but got TE exists")
}
}
func TestEnvMap_PrefixExists(t *testing.T) {
m := envMap{
"TEST": "1",
}
if !m.PrefixExists("TEST") {
t.Errorf("expected prefix TEST exists, but got prefix TEST not exists")
}
if !m.PrefixExists("TE") {
t.Errorf("expected prefix TE exists, but got prefix TE not exists")
}
if m.PrefixExists("TEST2") {
t.Errorf("expected prefix TEST2 not exists, but got prefix TEST2 exists")
}
}
func TestEnvMap_Get(t *testing.T) {
m := envMap{
"TEST": "1",
}
if m.Get("TEST") != "1" {
t.Errorf("expected '%s', but got '%s'", "1", m.Get("TEST"))
}
if m.Get("TE") != "" {
t.Errorf("expected '%s', but got '%s'", "", m.Get("TE"))
}
if m.Get("TEST2") != "" {
t.Errorf("expected '%s', but got '%s'", "", m.Get("TEST2"))
}
}
func TestEnvMap_GetPrefix(t *testing.T) {
m := envMap{
"TEST_": "1",
"TEST_1": "1",
"TE_ST1": "1",
}
type testDataType struct {
prefix string
out envMap
}
testData := []*testDataType{
{
prefix: "TEST",
out: map[string]string{
"": "1",
"1": "1",
},
},
{
prefix: "TE",
out: map[string]string{
"ST1": "1",
},
},
{
prefix: "TES_T2",
out: map[string]string{},
},
}
for _, datum := range testData {
out := m.GetPrefix(datum.prefix)
if !reflect.DeepEqual(datum.out, out) {
t.Errorf("expected '%v', but got '%v'", datum.out, out)
}
}
}
func TestEnvMap_GetSlicePrefixes(t *testing.T) {
type testDataType struct {
in envMap
out []string
}
testData := []*testDataType{
{
in: map[string]string{
"HELLO": "1",
"00": "123",
"100": "abc",
"_11": "abc",
},
out: []string{"00", "100"},
},
}
for _, datum := range testData {
out := datum.in.GetSlicePrefixes()
if !reflect.DeepEqual(datum.out, out) {
t.Errorf("expected '%v', but got '%v'", datum.out, out)
}
}
}