mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 16:43:07 +08:00
Tests: use t.Setenv
to set env vars (#69516)
This commit replaces `os.Setenv` with `t.Setenv` in tests. The environment variable is automatically restored to its original value when the test and all its subtests complete. Reference: https://pkg.go.dev/testing#T.Setenv Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package tracing
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -141,13 +140,8 @@ func TestTracingConfig(t *testing.T) {
|
||||
// export envioronment variables
|
||||
if test.Env != nil {
|
||||
for k, v := range test.Env {
|
||||
assert.NoError(t, os.Setenv(k, v))
|
||||
t.Setenv(k, v)
|
||||
}
|
||||
defer func() {
|
||||
for k := range test.Env {
|
||||
assert.NoError(t, os.Unsetenv(k))
|
||||
}
|
||||
}()
|
||||
}
|
||||
// parse config sections
|
||||
cfg := setting.NewCfg()
|
||||
|
Reference in New Issue
Block a user