check / check (push) Successful in 3m16s
Config tests, and the first-boot debug log test that builds a Config, start from an empty environment: config.ClearEnvForTest unsets every variable the process has and, when the test ends, leaves the environment exactly as it found it, so nothing exported in the developer's shell changes a result and nothing a test sets outlives it. TestEnvPositiveInt and TestEnvPort share one table runner, and TestEnvPort checks that the bad value appears in each error. Every out-of-range PORT now wraps ErrInvalidPort: zero, negatives, above 65535, and numbers too large or too small for an int. The README configuration table and the Settings page say that a RETENTION_SWEEP_INTERVAL that does not parse, or is zero or negative, fails startup. Model: opus-5-5
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package config_test
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"sneak.berlin/go/webhooker/internal/config"
|
|
)
|
|
|
|
// TestClearEnvForTest_RemovesAddedVariables pins that a variable set
|
|
// after the clear other than through t.Setenv, as a test's .env file
|
|
// sets one, is gone once the test ends, so it cannot reach the tests
|
|
// that run after it.
|
|
//
|
|
//nolint:paralleltest // ClearEnvForTest uses t.Setenv.
|
|
func TestClearEnvForTest_RemovesAddedVariables(t *testing.T) {
|
|
// The outer clear keeps a value of the key exported in the shell
|
|
// from making it a variable the inner clear has to put back.
|
|
config.ClearEnvForTest(t)
|
|
|
|
t.Run("loads a .env file after the clear", func(t *testing.T) {
|
|
config.ClearEnvForTest(t)
|
|
|
|
path := writeDotEnv(t, dotEnvKey+"=from-dot-env\n")
|
|
require.NoError(t, config.LoadDotEnvFileForTest(path))
|
|
require.Equal(t, "from-dot-env", os.Getenv(dotEnvKey))
|
|
})
|
|
|
|
_, present := os.LookupEnv(dotEnvKey)
|
|
assert.False(
|
|
t, present,
|
|
"a variable set after the clear must not outlive the test",
|
|
)
|
|
}
|