mirror of
https://github.com/caddyserver/caddy.git
synced 2026-08-04 14:58:47 +00:00
Added support for environment variables to 'templates' module. (#1035)
* * Added support for environment variables to 'templates' module. * Fixed flaw in test caused by environment variable ordering during testing on CI. * Updated some local variables to camel-case. * Reverted changes to replacer as environment variables are processed elsewhere. * Removed PrintEnv functionality in favour of documenting using template range.
This commit is contained in:
parent
eb3bbc409f
commit
45ac11088e
3 changed files with 43 additions and 2 deletions
|
|
@ -224,6 +224,28 @@ func TestHeader(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestEnv(t *testing.T) {
|
||||
context := getContextOrFail(t)
|
||||
|
||||
name := "ENV_TEST_NAME"
|
||||
testValue := "TEST_VALUE"
|
||||
os.Setenv(name, testValue)
|
||||
|
||||
notExisting := "ENV_TEST_NOT_EXISTING"
|
||||
os.Unsetenv(notExisting)
|
||||
|
||||
env := context.Env()
|
||||
if value := env[name]; value != testValue {
|
||||
t.Errorf("Expected env-variable %s value '%s', found '%s'",
|
||||
name, testValue, value)
|
||||
}
|
||||
|
||||
if value, ok := env[notExisting]; ok {
|
||||
t.Errorf("Expected empty env-variable %s, found '%s'",
|
||||
notExisting, value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIP(t *testing.T) {
|
||||
context := getContextOrFail(t)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue