From 5ed7580e2e2a73d83b541b37906f4562798e8fdd Mon Sep 17 00:00:00 2001 From: Miles Yucht Date: Thu, 23 Nov 2023 09:55:39 +0100 Subject: [PATCH] work --- cmd/auth/login.go | 4 +++- cmd/auth/login_test.go | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 cmd/auth/login_test.go diff --git a/cmd/auth/login.go b/cmd/auth/login.go index 8c6d52fcad..bbc88c1212 100644 --- a/cmd/auth/login.go +++ b/cmd/auth/login.go @@ -2,6 +2,7 @@ package auth import ( "context" + "errors" "fmt" "time" @@ -131,7 +132,8 @@ func setHost(ctx context.Context, profileName string, persistentAuth *auth.Persi _, profiles, err := databrickscfg.LoadProfiles(ctx, func(p databrickscfg.Profile) bool { return p.Name == profileName }) - if err != nil { + // Tolerate ErrNoConfiguration here, as we will write out a configuration as part of the login flow. + if !errors.Is(err, databrickscfg.ErrNoConfiguration) { return err } if persistentAuth.Host == "" { diff --git a/cmd/auth/login_test.go b/cmd/auth/login_test.go new file mode 100644 index 0000000000..9b834bd0a3 --- /dev/null +++ b/cmd/auth/login_test.go @@ -0,0 +1,17 @@ +package auth + +import ( + "context" + "testing" + + "github.com/databricks/cli/libs/auth" + "github.com/databricks/cli/libs/env" + "github.com/stretchr/testify/assert" +) + +func TestSetHostDoesNotFailWithNoDatabrickscfg(t *testing.T) { + ctx := context.Background() + ctx = env.Set(ctx, "DATABRICKS_CONFIG_FILE", "./imaginary-file/databrickscfg") + err := setHost(ctx, "foo", &auth.PersistentAuth{Host: "test"}, []string{}) + assert.NoError(t, err) +}