Use t.Setenv instead of custom implementation (#34)

Follow up for #18. This function was introduced in go1.17. As of #19 we
require go1.18, so we can use it.
This commit is contained in:
Pieter Noordhuis 2022-09-07 13:24:11 +02:00 committed by GitHub
parent 96efd0e2e4
commit 67b2e4206f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 27 deletions

View File

@ -8,7 +8,6 @@ import (
"testing"
"github.com/databricks/bricks/cmd/root"
"github.com/databricks/bricks/tests"
"github.com/stretchr/testify/assert"
"gopkg.in/ini.v1"
)
@ -25,8 +24,8 @@ func setup(t *testing.T) string {
if runtime.GOOS == "windows" {
homeEnvVar = "USERPROFILE"
}
tests.SetTestEnv(t, homeEnvVar, tempHomeDir)
tests.SetTestEnv(t, "DATABRICKS_CONFIG_FILE", "")
t.Setenv(homeEnvVar, tempHomeDir)
t.Setenv("DATABRICKS_CONFIG_FILE", "")
return tempHomeDir
}
@ -74,7 +73,7 @@ func TestConfigFileFromEnvNoInteractive(t *testing.T) {
ctx := context.Background()
tempHomeDir := setup(t)
cfgFileDir := filepath.Join(tempHomeDir, "test")
tests.SetTestEnv(t, "DATABRICKS_CONFIG_FILE", cfgFileDir)
t.Setenv("DATABRICKS_CONFIG_FILE", cfgFileDir)
inp := getTempFileWithContent(t, tempHomeDir, "token\n")
oldStdin := os.Stdin

View File

@ -1,23 +0,0 @@
package tests
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func SetTestEnv(t *testing.T, key, value string) {
originalValue, isSet := os.LookupEnv(key)
err := os.Setenv(key, value)
assert.NoError(t, err)
t.Cleanup(func() {
if isSet {
os.Setenv(key, originalValue)
} else {
os.Unsetenv(key)
}
})
}