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
155
156
157
158
159
160
161
162
|
package env
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSlice(t *testing.T) {
goodMap := make(map[string]string, 0)
goodMap["apple"] = "red"
goodMap["banana"] = "yellow"
goodMap["pear"] = ""
goodResult := []string{"apple=red", "banana=yellow", "pear"}
type args struct {
m map[string]string
}
tests := []struct {
name string
args args
want []string
}{
{
name: "Good",
args: args{
m: goodMap,
},
want: goodResult,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.ElementsMatchf(t, Slice(tt.args.m), tt.want, "Slice() = %v, want %v", Slice(tt.args.m), tt.want)
})
}
}
func TestJoin(t *testing.T) {
firstMap := make(map[string]string, 0)
firstMap["apple"] = "red"
secondMap := make(map[string]string, 0)
secondMap["banana"] = "yellow"
goodResult := make(map[string]string, 0)
goodResult["apple"] = "red"
goodResult["banana"] = "yellow"
overrideResult := make(map[string]string, 0)
overrideResult["apple"] = "green"
overrideResult["banana"] = "yellow"
overrideMap := make(map[string]string, 0)
overrideMap["banana"] = "yellow"
overrideMap["apple"] = "green"
type args struct {
base map[string]string
override map[string]string
}
tests := []struct {
name string
args args
want map[string]string
}{
{
name: "GoodJoin",
args: args{
base: firstMap,
override: secondMap,
},
want: goodResult,
},
{
name: "GoodOverride",
args: args{
base: firstMap,
override: overrideMap,
},
want: overrideResult,
},
{
name: "EmptyOverride",
args: args{
base: firstMap,
override: nil,
},
want: firstMap,
},
{
name: "EmptyBase",
args: args{
base: nil,
override: firstMap,
},
want: firstMap,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := Join(tt.args.base, tt.args.override)
assert.EqualValuesf(t, got, tt.want, "Join() = %v, want %v", got, tt.want)
})
}
}
func Test_parseEnv(t *testing.T) {
good := make(map[string]string)
type args struct {
env map[string]string
line string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "Good",
args: args{
env: good,
line: "apple=red",
},
wantErr: false,
},
{
name: "GoodNoValue",
args: args{
env: good,
line: "apple=",
},
wantErr: false,
},
{
name: "GoodNoKeyNoValue",
args: args{
env: good,
line: "=",
},
wantErr: true,
},
{
name: "BadNoKey",
args: args{
env: good,
line: "=foobar",
},
wantErr: true,
},
{
name: "BadOnlyDelim",
args: args{
env: good,
line: "=",
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := parseEnv(tt.args.env, tt.args.line); (err != nil) != tt.wantErr {
t.Errorf("parseEnv() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
|