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