(t *testing.T)
| 372 | } |
| 373 | |
| 374 | func TestReplacerNew(t *testing.T) { |
| 375 | repl := NewReplacer() |
| 376 | |
| 377 | if len(repl.providers) != 3 { |
| 378 | t.Errorf("Expected providers length '%v' got length '%v'", 3, len(repl.providers)) |
| 379 | } |
| 380 | |
| 381 | // test if default global replacements are added as the first provider |
| 382 | hostname, _ := os.Hostname() |
| 383 | wd, _ := os.Getwd() |
| 384 | os.Setenv("CADDY_REPLACER_TEST", "envtest") |
| 385 | defer os.Setenv("CADDY_REPLACER_TEST", "") |
| 386 | |
| 387 | for _, tc := range []struct { |
| 388 | variable string |
| 389 | value string |
| 390 | }{ |
| 391 | { |
| 392 | variable: "system.hostname", |
| 393 | value: hostname, |
| 394 | }, |
| 395 | { |
| 396 | variable: "system.slash", |
| 397 | value: string(filepath.Separator), |
| 398 | }, |
| 399 | { |
| 400 | variable: "system.os", |
| 401 | value: runtime.GOOS, |
| 402 | }, |
| 403 | { |
| 404 | variable: "system.arch", |
| 405 | value: runtime.GOARCH, |
| 406 | }, |
| 407 | { |
| 408 | variable: "system.wd", |
| 409 | value: wd, |
| 410 | }, |
| 411 | { |
| 412 | variable: "env.CADDY_REPLACER_TEST", |
| 413 | value: "envtest", |
| 414 | }, |
| 415 | } { |
| 416 | if val, ok := repl.providers[0].replace(tc.variable); ok { |
| 417 | if val != tc.value { |
| 418 | t.Errorf("Expected value '%s' for key '%s' got '%s'", tc.value, tc.variable, val) |
| 419 | } |
| 420 | } else { |
| 421 | t.Errorf("Expected key '%s' to be recognized by first provider", tc.variable) |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | // test if file provider is added as the second provider |
| 426 | for _, tc := range []struct { |
| 427 | variable string |
| 428 | value string |
| 429 | }{ |
| 430 | { |
| 431 | variable: "file.caddytest/integration/testdata/foo.txt", |
nothing calls this directly
no test coverage detected