From 1629ba1f5cf7715566758b3d088e968d61b5bbb7 Mon Sep 17 00:00:00 2001 From: sneak Date: Mon, 28 Sep 2026 13:18:04 +0000 Subject: [PATCH] test: an unknown PIXA_ environment variable aborts startup (closes #133) Tests, written before the change, for the check of PIXA_ names at startup: a PIXA_ variable that is not a setting's variable aborts naming it, PIXA_PORT aborts with a message saying to use PORT, and PIXA_CONFIG_PATH and every setting's variable are accepted. They call validateKnownEnvVars, which the change adds, so the package does not build until it lands. Model: opus-5-5 --- internal/config/env_internal_test.go | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/internal/config/env_internal_test.go b/internal/config/env_internal_test.go index ea1e361..7ab39fa 100644 --- a/internal/config/env_internal_test.go +++ b/internal/config/env_internal_test.go @@ -95,6 +95,43 @@ 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 := validateKnownEnvVars() + 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 := validateKnownEnvVars() + wantStartupError(t, err, "PIXA_PORT", "use PORT") +} + +// TestSettingVariablesAndConfigPathAreAccepted checks that every +// setting's variable and PIXA_CONFIG_PATH pass the check for unknown +// PIXA_ variables. TestEnvironmentSetsEveryKey pins the names in the list. +func TestSettingVariablesAndConfigPathAreAccepted(t *testing.T) { + t.Setenv("PIXA_CONFIG_PATH", "/etc/pixa/config.yml") + + for _, name := range envVarNames() { + t.Setenv(name, "") + } + + err := validateKnownEnvVars() + if err != nil { + t.Fatalf("PIXA_CONFIG_PATH and every setting's variable "+ + "must be accepted: %v", err) + } +} + // TestPortFromEnvironmentOverridesConfigFile checks that PORT wins over // the port in the config file. func TestPortFromEnvironmentOverridesConfigFile(t *testing.T) {