mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 03:21:51 +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:
@ -2,7 +2,6 @@ package plugins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -55,11 +54,7 @@ func TestConfigReader(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
err := os.Setenv("ENABLE_PLUGIN_VAR", "test-plugin")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
_ = os.Unsetenv("ENABLE_PLUGIN_VAR")
|
||||
})
|
||||
t.Setenv("ENABLE_PLUGIN_VAR", "test-plugin")
|
||||
|
||||
cfgProvider := newConfigReader(log.New("test logger"), pm)
|
||||
cfg, err := cfgProvider.readConfig(context.Background(), correctProperties)
|
||||
|
Reference in New Issue
Block a user