diff --git a/cmd/auth/describe.go b/cmd/auth/describe.go index 1f11df319e..3a6e3d5d77 100644 --- a/cmd/auth/describe.go +++ b/cmd/auth/describe.go @@ -23,7 +23,7 @@ var authTemplate = `{{"Host:" | bold}} {{.Status.Details.Host}} ----- ` + configurationTemplate -var errorTemplate = `Unable to authenticate: {{.Error}} +var errorTemplate = `Unable to authenticate: {{.Status.Error}} ----- ` + configurationTemplate diff --git a/internal/auth_describe_test.go b/internal/auth_describe_test.go new file mode 100644 index 0000000000..90b5d68019 --- /dev/null +++ b/internal/auth_describe_test.go @@ -0,0 +1,49 @@ +package internal + +import ( + "context" + "fmt" + "testing" + + "github.com/databricks/databricks-sdk-go" + "github.com/stretchr/testify/require" +) + +func TestAuthDescribeSuccess(t *testing.T) { + t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV")) + + stdout, _ := RequireSuccessfulRun(t, "auth", "describe") + outStr := stdout.String() + + w, err := databricks.NewWorkspaceClient(&databricks.Config{}) + require.NoError(t, err) + + require.NotEmpty(t, outStr) + require.Contains(t, outStr, fmt.Sprintf("Host: %s", w.Config.Host)) + + me, err := w.CurrentUser.Me(context.Background()) + require.NoError(t, err) + require.Contains(t, outStr, fmt.Sprintf("User: %s", me.UserName)) + require.Contains(t, outStr, fmt.Sprintf("Authenticated with: %s", w.Config.AuthType)) + require.Contains(t, outStr, "Current configuration:") + require.Contains(t, outStr, fmt.Sprintf("✓ host: %s", w.Config.Host)) + require.Contains(t, outStr, "✓ profile: default") +} + +func TestAuthDescribeFailure(t *testing.T) { + t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV")) + + stdout, _ := RequireSuccessfulRun(t, "auth", "describe", "--profile", "nonexistent") + outStr := stdout.String() + + require.NotEmpty(t, outStr) + require.Contains(t, outStr, "Unable to authenticate: resolve") + require.Contains(t, outStr, "has no nonexistent profile configured") + require.Contains(t, outStr, "Current configuration:") + + w, err := databricks.NewWorkspaceClient(&databricks.Config{}) + require.NoError(t, err) + + require.Contains(t, outStr, fmt.Sprintf("✓ host: %s", w.Config.Host)) + require.Contains(t, outStr, "✓ profile: nonexistent (from --profile flag)") +}