| 199 | } |
| 200 | |
| 201 | func TestExpandEnv(t *testing.T) { |
| 202 | var tests = []struct { |
| 203 | in string |
| 204 | out string |
| 205 | }{ |
| 206 | // Environment variables can be specified as ${env} or $env. |
| 207 | {"x$y", "xy"}, |
| 208 | {"x${y}", "xy"}, |
| 209 | |
| 210 | // Environment variables are case-sensitive. Neither are replaced. |
| 211 | {"x$Y", "x"}, |
| 212 | {"x${Y}", "x"}, |
| 213 | |
| 214 | // Defaults can only be specified when using braces. |
| 215 | {"x${Z:D}", "xD"}, |
| 216 | {"x${Z:A B C D}", "xA B C D"}, // Spaces are allowed in the default. |
| 217 | {"x${Z:}", "x"}, |
| 218 | |
| 219 | // Defaults don't work unless braces are used. |
| 220 | {"x$y:D", "xy:D"}, |
| 221 | } |
| 222 | |
| 223 | for _, test := range tests { |
| 224 | t.Run(test.in, func(t *testing.T) { |
| 225 | _ = os.Setenv("y", "y") |
| 226 | output := expandEnv([]byte(test.in)) |
| 227 | assert.Equal(t, test.out, string(output), "Input: %s", test.in) |
| 228 | }) |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | func TestParseConfigFileParameter(t *testing.T) { |
| 233 | var tests = []struct { |