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", ) }