From 73b86b592964d5b7f081698f7886f9afa95b8338 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 6 Jan 2025 14:30:38 +0100 Subject: [PATCH] Use USERPROFILE on Windows --- acceptance/acceptance_test.go | 3 ++- libs/env/context.go | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 4736352879..24701216d9 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -16,6 +16,7 @@ import ( "time" "github.com/databricks/cli/internal/testutil" + "github.com/databricks/cli/libs/env" "github.com/databricks/cli/libs/testdiff" "github.com/stretchr/testify/require" ) @@ -32,7 +33,7 @@ func TestAll(t *testing.T) { t.Setenv("DATABRICKS_TOKEN", "dapi1234") homeDir := t.TempDir() - t.Setenv("HOME", homeDir) + t.Setenv(env.HomeEnvVar(), homeDir) testDirs := getTests(t) require.NotEmpty(t, testDirs) diff --git a/libs/env/context.go b/libs/env/context.go index af4d1afa02..37b76147a3 100644 --- a/libs/env/context.go +++ b/libs/env/context.go @@ -65,7 +65,7 @@ func Set(ctx context.Context, key, value string) context.Context { return setMap(ctx, m) } -func homeEnvVar() string { +func HomeEnvVar() string { if runtime.GOOS == "windows" { return "USERPROFILE" } @@ -73,14 +73,14 @@ func homeEnvVar() string { } func WithUserHomeDir(ctx context.Context, value string) context.Context { - return Set(ctx, homeEnvVar(), value) + return Set(ctx, HomeEnvVar(), value) } // ErrNoHomeEnv indicates the absence of $HOME env variable var ErrNoHomeEnv = errors.New("$HOME is not set") func UserHomeDir(ctx context.Context) (string, error) { - home := Get(ctx, homeEnvVar()) + home := Get(ctx, HomeEnvVar()) if home == "" { return "", ErrNoHomeEnv }