mirror of https://github.com/databricks/cli.git
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:
parent
96efd0e2e4
commit
67b2e4206f
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue