-
Notifications
You must be signed in to change notification settings - Fork 68
/
internals_test.go
77 lines (74 loc) · 1.6 KB
/
internals_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
package imagebuilder
import (
"fmt"
"sort"
"strings"
"testing"
)
func TestMergeEnv(t *testing.T) {
tests := [][3][]string{
{
[]string{"A=B", "B=C", "C=D"},
nil,
[]string{"A=B", "B=C", "C=D"},
},
{
nil,
[]string{"A=B", "B=C", "C=D"},
[]string{"A=B", "B=C", "C=D"},
},
{
[]string{"A=B", "B=C", "C=D", "E=F"},
[]string{"B=O", "F=G"},
[]string{"A=B", "B=O", "C=D", "E=F", "F=G"},
},
}
for i, test := range tests {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
result := mergeEnv(test[0], test[1])
if len(result) != len(test[2]) {
t.Fatalf("expected %v, got %v", test[2], result)
}
for i := range result {
if result[i] != test[2][i] {
t.Fatalf("expected %v, got %v", test[2], result)
}
}
})
}
}
func TestEnvMapAsSlice(t *testing.T) {
tests := [][2][]string{
{
[]string{"A=B", "B=C", "C=D"},
[]string{"A=B", "B=C", "C=D"},
},
{
[]string{"A=B", "B=C", "C=D", "E=F", "B=O", "F=G"},
[]string{"A=B", "B=O", "C=D", "E=F", "F=G"},
},
{
[]string{"A=B", "C=D", "B=C", "E=F", "F=G", "B=O"},
[]string{"A=B", "B=O", "C=D", "E=F", "F=G"},
},
}
for i, test := range tests {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
m := make(map[string]string)
for _, spec := range test[0] {
s := strings.SplitN(spec, "=", 2)
m[s[0]] = s[1]
}
result := envMapAsSlice(m)
sort.Strings(result)
if len(result) != len(test[1]) {
t.Fatalf("expected %v, got %v", test[1], result)
}
for i := range result {
if result[i] != test[1][i] {
t.Fatalf("expected %v, got %v", test[1], result)
}
}
})
}
}