Settings: Fix data race when dynamically overriding settings with environment variables (#81667)

Chore: Fix data race when dynamically overriding settings with environment variables
This commit is contained in:
Diego Augusto Molina
2024-02-05 12:25:54 -03:00
committed by GitHub
parent c87e4eb724
commit b02f0b926a
4 changed files with 135 additions and 7 deletions

View File

@ -0,0 +1,35 @@
package osutil
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRealEnv(t *testing.T) {
// testing here is obviously not parallel since we do need to access real
// environment variables from the os
const key = "MEREKETENGUE"
const value = "IS ALIVE"
assert.Equal(t, os.Getenv(key), RealEnv{}.Getenv(key))
assert.NoError(t, RealEnv{}.Setenv(key, value))
assert.Equal(t, value, RealEnv{}.Getenv(key))
assert.Equal(t, value, os.Getenv(key))
}
func TestMapEnv(t *testing.T) {
t.Parallel()
const key = "THE_THING"
const value = "IS ALIVE"
e := MapEnv{}
assert.Empty(t, e.Getenv(key))
assert.Len(t, e, 0)
assert.NoError(t, e.Setenv(key, value))
assert.Equal(t, value, e.Getenv(key))
assert.Len(t, e, 1)
}