|
1 | 1 | package config
|
2 | 2 |
|
3 |
| -import "testing" |
4 |
| -import "time" |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + "time" |
| 6 | +) |
5 | 7 |
|
6 | 8 | func TestNew(t *testing.T) {
|
7 | 9 | defaults, err := New([]string{})
|
@@ -123,6 +125,93 @@ func Test_FunctionProcessAlternativeName(t *testing.T) {
|
123 | 125 | }
|
124 | 126 | }
|
125 | 127 |
|
| 128 | +func Test_FunctionProcessWithTargetArgument(t *testing.T) { |
| 129 | + env := []string{ |
| 130 | + `fprocess=node index.js`, |
| 131 | + } |
| 132 | + wantProcess := "node" |
| 133 | + wantArguments := []string{"index.js"} |
| 134 | + |
| 135 | + actual, err := New(env) |
| 136 | + if err != nil { |
| 137 | + t.Errorf("Expected no errors") |
| 138 | + } |
| 139 | + |
| 140 | + process, args := actual.Process() |
| 141 | + if process != wantProcess { |
| 142 | + t.Errorf("Want process %v, got: %v", wantProcess, process) |
| 143 | + } |
| 144 | + |
| 145 | + if len(args) != len(wantArguments) { |
| 146 | + t.Errorf("Want %d args, got: %d args", len(wantArguments), len(args)) |
| 147 | + t.Fail() |
| 148 | + } |
| 149 | + |
| 150 | + for i, wantArg := range wantArguments { |
| 151 | + if args[i] != wantArg { |
| 152 | + t.Errorf("Want arg%d: %s, got: %s", i, wantArg, args[i]) |
| 153 | + } |
| 154 | + } |
| 155 | +} |
| 156 | + |
| 157 | +func Test_FunctionProcessWithFlag(t *testing.T) { |
| 158 | + env := []string{ |
| 159 | + `fprocess=node --this-is-a-flag`, |
| 160 | + } |
| 161 | + wantProcess := "node" |
| 162 | + wantArguments := []string{"--this-is-a-flag"} |
| 163 | + |
| 164 | + actual, err := New(env) |
| 165 | + if err != nil { |
| 166 | + t.Errorf("Expected no errors") |
| 167 | + } |
| 168 | + |
| 169 | + process, args := actual.Process() |
| 170 | + if process != wantProcess { |
| 171 | + t.Errorf("Want process %v, got: %v", wantProcess, process) |
| 172 | + } |
| 173 | + |
| 174 | + if len(args) != len(wantArguments) { |
| 175 | + t.Errorf("Want %d args, got: %d args", len(wantArguments), len(args)) |
| 176 | + t.Fail() |
| 177 | + } |
| 178 | + |
| 179 | + for i, wantArg := range wantArguments { |
| 180 | + if args[i] != wantArg { |
| 181 | + t.Errorf("Want arg%d: %s, got: %s", i, wantArg, args[i]) |
| 182 | + } |
| 183 | + } |
| 184 | +} |
| 185 | + |
| 186 | +func Test_FunctionProcessWithFlagAndValue(t *testing.T) { |
| 187 | + env := []string{ |
| 188 | + `fprocess=node --this-is-a-flag=1234`, |
| 189 | + } |
| 190 | + wantProcess := "node" |
| 191 | + wantArguments := []string{"--this-is-a-flag=1234"} |
| 192 | + |
| 193 | + actual, err := New(env) |
| 194 | + if err != nil { |
| 195 | + t.Errorf("Expected no errors") |
| 196 | + } |
| 197 | + |
| 198 | + process, args := actual.Process() |
| 199 | + if process != wantProcess { |
| 200 | + t.Errorf("Want process %v, got: %v", wantProcess, process) |
| 201 | + } |
| 202 | + |
| 203 | + if len(args) != len(wantArguments) { |
| 204 | + t.Errorf("Want %d args, got: %d args", len(wantArguments), len(args)) |
| 205 | + t.Fail() |
| 206 | + } |
| 207 | + |
| 208 | + for i, wantArg := range wantArguments { |
| 209 | + if args[i] != wantArg { |
| 210 | + t.Errorf("Want arg%d: %s, got: %s", i, wantArg, args[i]) |
| 211 | + } |
| 212 | + } |
| 213 | +} |
| 214 | + |
126 | 215 | func Test_PortOverride(t *testing.T) {
|
127 | 216 | env := []string{
|
128 | 217 | "port=8081",
|
|
0 commit comments