diff --git a/internal/config/env_internal_test.go b/internal/config/env_internal_test.go index ea1e361..11b7d82 100644 --- a/internal/config/env_internal_test.go +++ b/internal/config/env_internal_test.go @@ -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) {