-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcommand_test.go
More file actions
86 lines (82 loc) · 1.53 KB
/
command_test.go
File metadata and controls
86 lines (82 loc) · 1.53 KB
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
package pipe
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCopyEnvWithOverride(t *testing.T) {
examples := []struct {
label string
env []string
overrides map[string]string
expectedResult []string
}{
{
label: "empty",
overrides: map[string]string{}, // can't be nil
},
{
label: "original env only",
env: []string{
"A=B",
"B=C",
},
overrides: map[string]string{},
expectedResult: []string{
"A=B",
"B=C",
},
},
{
label: "overrides only",
env: []string{},
overrides: map[string]string{
"A": "B",
"B": "C",
},
expectedResult: []string{
"A=B",
"B=C",
},
},
{
label: "mix of overrides and not",
env: []string{
"ORIGINAL1=abc",
"ORIGINAL2=def",
},
overrides: map[string]string{
"ORIGINAL1": "override1",
"OVERRIDE1": "also override",
},
expectedResult: []string{
"ORIGINAL1=override1",
"ORIGINAL2=def",
"OVERRIDE1=also override",
},
},
{
label: "random equal signs",
env: []string{
"ORIGINAL1=abc=foo",
"ORIGINAL2=def=bar",
},
overrides: map[string]string{
"ORIGINAL1": "new=new-new",
"OVERRIDE1": "also=new-new",
},
expectedResult: []string{
"ORIGINAL1=new=new-new",
"ORIGINAL2=def=bar",
"OVERRIDE1=also=new-new",
},
},
}
for _, ex := range examples {
ex := ex
t.Run(ex.label, func(t *testing.T) {
assert.ElementsMatch(t, ex.expectedResult,
copyEnvWithOverrides(ex.env, ex.overrides),
)
})
}
}