-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils_test.go
96 lines (91 loc) · 1.7 KB
/
utils_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
package main
import "testing"
func Test_parseEnvLine(t *testing.T) {
tests := []struct {
name string
line string
wantKey string
wantValue string
wantErr bool
}{
{
name: "empty",
line: "",
wantKey: "",
wantValue: "",
},
{
name: "comment",
line: "# comment",
wantKey: "",
wantValue: "",
},
{
name: "comment with space",
line: " # comment",
wantKey: "",
wantValue: "",
},
{
name: "key lowercase and value",
line: "key=value",
wantKey: "KEY",
wantValue: "value",
},
{
name: "key uppercase and value",
line: "KEY=value",
wantKey: "KEY",
wantValue: "value",
},
{
name: "multi-equals",
line: "KEY=value=1",
wantKey: "KEY",
wantValue: "value=1",
},
{
name: "no key",
line: "=value1",
wantErr: true,
},
{
name: "no separator",
line: "KEYvalue1",
wantErr: true,
},
{
name: "no value",
line: "KEY=",
wantKey: "KEY",
wantValue: "",
},
{
name: "no value with space",
line: "KEY= ",
wantKey: "KEY",
wantValue: "",
},
{
name: "quoted value",
line: "KEY=\"value1\"",
wantKey: "KEY",
wantValue: "value1",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotKey, gotValue, err := parseEnvLine(tt.line)
if (err != nil) != tt.wantErr {
t.Errorf("error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotKey != tt.wantKey {
t.Errorf("got key = %q, want %q", gotKey, tt.wantKey)
}
if gotValue != tt.wantValue {
t.Errorf("got value = %q, want %q", gotValue, tt.wantValue)
}
})
}
}