-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_test.go
113 lines (105 loc) · 2.04 KB
/
main_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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"reflect"
"testing"
)
func TestEmbedExec(t *testing.T) {
tests := map[string]struct {
input string
execs []string
args [][]string
}{
"no input": {
input: "",
execs: []string{},
args: [][]string{},
},
"with argument input": {
input: `foo:"bar"`,
execs: []string{
"foo",
},
args: [][]string{
{"bar"},
},
},
"with multiple argument inputs": {
input: `go:"-123 -456 -789"`,
execs: []string{
"go",
},
args: [][]string{
{"-123", "-456", "-789"},
},
},
"without arguments": {
input: `bazinga`,
execs: []string{
"bazinga",
},
args: [][]string{
{},
},
},
}
for name, tc := range tests {
name := name
tc := tc
t.Run(name, func(t *testing.T) {
// Reset package global variables
execs = []string{}
args = [][]string{}
if err := embedExec(tc.input); err != nil {
t.Fatalf("expected no error but got: %v", err)
}
if !reflect.DeepEqual(execs, tc.execs) {
t.Fatalf("expected executables did not match. "+
"Got: %#v\nExpected: %#v", execs, tc.execs)
}
if !reflect.DeepEqual(args, tc.args) {
t.Fatalf("expected arguments did not match. "+
"Got: %#v\nExpected: %#v", args, tc.args)
}
})
}
}
func TestEmbedEnvVar(t *testing.T) {
tests := map[string]struct {
input string
env map[string]string
}{
"no input": {
input: "",
env: make(map[string]string),
},
"without value": {
input: "key",
env: map[string]string{
"key": "TRUE",
},
},
"key=value": {
input: "key=value",
env: map[string]string{
"key": "value",
},
},
}
for name, tc := range tests {
name := name
tc := tc
t.Run(name, func(t *testing.T) {
// Reset package global variables
for k := range env {
delete(env, k)
}
if err := embedEnvVar(tc.input); err != nil {
t.Fatalf("expected no error but got: %v", err)
}
if !reflect.DeepEqual(env, tc.env) {
t.Fatalf("expected environment variables did not match. "+
"Got: %#v\nExpected: %#v", env, tc.env)
}
})
}
}