mirror of
https://github.com/grafana/grafana.git
synced 2025-08-03 06:51:13 +08:00
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:

committed by
GitHub

parent
c87e4eb724
commit
b02f0b926a
35
pkg/util/osutil/osutil_test.go
Normal file
35
pkg/util/osutil/osutil_test.go
Normal 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)
|
||||
}
|
Reference in New Issue
Block a user