check / check (push) Waiting to run
The config tests unset variables without restoring them and read whatever the developer's shell exported, so results could differ from one machine to the next. config.ClearEnvForTest, in internal/config/testing.go, unsets every variable in the process environment and, when the test ends, leaves it exactly as it found it; every config test and the first-boot test call it before setting their own. TestEnvPositiveInt and TestEnvPort share one table runner, and the port errors name the bad value. A PORT of zero, below zero, or too large to parse now matches ErrInvalidPort, as one above 65535 already did. The README and the Settings page say an unparseable or non-positive RETENTION_SWEEP_INTERVAL stops 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",
|
|
)
|
|
}
|