forked from constabulary/gb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv_test.go
More file actions
49 lines (44 loc) · 873 Bytes
/
Copy pathenv_test.go
File metadata and controls
49 lines (44 loc) · 873 Bytes
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
package cmd
import "testing"
func TestMergeEnv(t *testing.T) {
envTests := []struct {
env []string
args map[string]string
want []string
}{
{
env: nil,
args: nil,
want: nil,
},
{
env: []string{`FOO=BAR`, `BAZ="QUXX"`},
args: nil,
want: []string{`FOO=BAR`, `BAZ="QUXX"`},
},
{
env: []string{`FOO=BAR`, `BAZ="QUXX"`},
args: map[string]string{"BLORT": "false", "BAZ": "QUXX"},
want: []string{`FOO=BAR`, `BAZ=QUXX`, `BLORT=false`},
},
}
for _, tt := range envTests {
got := MergeEnv(tt.env, tt.args)
compare(t, tt.want, got)
}
}
func compare(t *testing.T, want, got []string) {
w, g := set(want), set(got)
for k := range w {
if w[k] != g[k] {
t.Errorf("want %v, got %v", k, g[k])
}
}
}
func set(v []string) map[string]bool {
m := make(map[string]bool)
for _, s := range v {
m[s] = true
}
return m
}