test: an unknown PIXA_ environment variable aborts startup (closes #133)
check / check (push) Failing after 1m57s
check / check (push) Failing after 1m57s
Tests, written before the change: a PIXA_ variable that is not a setting's variable aborts startup naming it, and PIXA_PORT aborts with a message saying to use PORT. Both fail until the change lands. The test that sets every setting's variable now also sets PIXA_CONFIG_PATH, so it shows that none of those names is rejected. Model: opus-5-5
This commit is contained in:
@@ -49,7 +49,10 @@ func wantStartupError(t *testing.T, err error, wants ...string) {
|
||||
// TestEnvironmentSetsEveryKey sets every key from its environment
|
||||
// variable, with no config file at all: PORT for the port, and PIXA_
|
||||
// plus the key in upper case, "." written as "_", for every other key.
|
||||
// It also sets PIXA_CONFIG_PATH, so it shows that none of these PIXA_
|
||||
// names is rejected as unknown.
|
||||
func TestEnvironmentSetsEveryKey(t *testing.T) {
|
||||
t.Setenv("PIXA_CONFIG_PATH", "/etc/pixa/config.yml")
|
||||
t.Setenv("PIXA_DEBUG", "true")
|
||||
t.Setenv("PIXA_MAINTENANCE_MODE", "1")
|
||||
t.Setenv("PORT", "9090")
|
||||
@@ -95,6 +98,26 @@ func TestEnvironmentSetsEveryKey(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestUnknownPixaVariableAbortsStartup checks that a PIXA_ variable that
|
||||
// is not a setting's variable, such as a misspelled one, aborts startup
|
||||
// naming it, as an unknown config key does, instead of being ignored.
|
||||
func TestUnknownPixaVariableAbortsStartup(t *testing.T) {
|
||||
t.Setenv("PIXA_TRUSTED_PROXY", "192.0.2.0/24")
|
||||
t.Setenv("PIXA_SIGNINGKEY", validTestSigningKey)
|
||||
|
||||
_, err := configFromYAML(t, signingKeyLine)
|
||||
wantStartupError(t, err, "PIXA_TRUSTED_PROXY", "PIXA_SIGNINGKEY")
|
||||
}
|
||||
|
||||
// TestPixaPortAbortsStartupPointingToPort checks that PIXA_PORT aborts
|
||||
// startup with a message saying to use PORT, which sets the port.
|
||||
func TestPixaPortAbortsStartupPointingToPort(t *testing.T) {
|
||||
t.Setenv("PIXA_PORT", "9090")
|
||||
|
||||
_, err := configFromYAML(t, signingKeyLine)
|
||||
wantStartupError(t, err, "PIXA_PORT", "use PORT")
|
||||
}
|
||||
|
||||
// TestPortFromEnvironmentOverridesConfigFile checks that PORT wins over
|
||||
// the port in the config file.
|
||||
func TestPortFromEnvironmentOverridesConfigFile(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user