Skip to content

Commit d870502

Browse files
committed
Remove custom config loaders and add acceptance test
Remove the custom Loaders override in resolveConfig. The CLI's env.NewConfigLoader panics on non-string config attributes (e.g. DATABRICKS_RATE_LIMIT which is an int), and the SDK's default loaders already handle env vars properly. This aligns with how cmd/root/auth.go creates config objects. Also add an acceptance test under acceptance/cmd/doctor/ that exercises the full doctor flow with a mock HTTP server. Co-authored-by: Isaac
1 parent 2ee6693 commit d870502

6 files changed

Lines changed: 51 additions & 15 deletions

File tree

acceptance/cmd/doctor/out.test.toml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

acceptance/cmd/doctor/output.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
=== Doctor with --profile flag
3+
4+
>>> [CLI] doctor --profile my-workspace --output json
5+
CLI Version: info - [DEV_VERSION]
6+
Config File: pass - ~/.databrickscfg (1 profiles)
7+
Current Profile: info - my-workspace
8+
Authentication: pass - OK (pat)
9+
Identity: pass - test@example.com
10+
Network: pass - [DATABRICKS_URL] is reachable

acceptance/cmd/doctor/script

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
sethome "./home"
2+
3+
cat > "./home/.databrickscfg" <<EOF
4+
[my-workspace]
5+
host = $DATABRICKS_HOST
6+
token = $DATABRICKS_TOKEN
7+
EOF
8+
9+
title "Doctor with --profile flag\n"
10+
trace $CLI doctor --profile my-workspace --output json | jq -r '.[] | "\(.name): \(.status) - \(.message)"'

acceptance/cmd/doctor/test.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Local = true
2+
Cloud = false
3+
4+
Ignore = [
5+
"home"
6+
]
7+
8+
[[Server]]
9+
Pattern = "GET /api/2.0/preview/scim/v2/Me"
10+
Response.Body = '''
11+
{
12+
"userName": "test@example.com"
13+
}
14+
'''
15+
16+
[[Server]]
17+
Pattern = "HEAD /"
18+
Response.Body = ''

cmd/doctor/checks.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,6 @@ func resolveConfig(cmd *cobra.Command) (*config.Config, error) {
149149
cfg.ConfigFile = configFile
150150
}
151151

152-
cfg.Loaders = []config.Loader{
153-
env.NewConfigLoader(ctx),
154-
config.ConfigAttributes,
155-
config.ConfigFile,
156-
}
157-
158152
profileFlag := cmd.Flag("profile")
159153
if profileFlag != nil && profileFlag.Changed {
160154
cfg.Profile = profileFlag.Value.String()

cmd/doctor/doctor_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -281,20 +281,18 @@ func TestCheckAuthAccountLevel(t *testing.T) {
281281
assert.NotNil(t, authCfg)
282282
}
283283

284-
func TestResolveConfigUsesCommandContextEnv(t *testing.T) {
284+
func TestResolveConfigUsesEnvVars(t *testing.T) {
285285
clearConfigEnv(t)
286-
t.Setenv("DATABRICKS_HOST", "https://real.example.com")
287-
t.Setenv("DATABRICKS_TOKEN", "real-token")
286+
t.Setenv("DATABRICKS_HOST", "https://env.example.com")
287+
t.Setenv("DATABRICKS_TOKEN", "env-token")
288288

289289
ctx := cmdio.MockDiscard(t.Context())
290-
ctx = env.Set(ctx, "DATABRICKS_HOST", "https://context.example.com")
291-
ctx = env.Set(ctx, "DATABRICKS_TOKEN", "context-token")
292290
cmd := newTestCmd(ctx)
293291

294292
cfg, err := resolveConfig(cmd)
295293
require.NoError(t, err)
296-
assert.Equal(t, "https://context.example.com", cfg.Host)
297-
assert.Equal(t, "context-token", cfg.Token)
294+
assert.Equal(t, "https://env.example.com", cfg.Host)
295+
assert.Equal(t, "env-token", cfg.Token)
298296
}
299297

300298
func TestCheckIdentitySuccess(t *testing.T) {
@@ -512,9 +510,10 @@ func TestCheckNetworkConfigResolutionFailureNoHost(t *testing.T) {
512510
err := os.WriteFile(configFile, []byte("[DEFAULT]\nhost = https://example.com\n"), 0o600)
513511
require.NoError(t, err)
514512

513+
t.Setenv("DATABRICKS_CONFIG_FILE", configFile)
514+
t.Setenv("DATABRICKS_CONFIG_PROFILE", "missing")
515+
515516
ctx := cmdio.MockDiscard(t.Context())
516-
ctx = env.Set(ctx, "DATABRICKS_CONFIG_FILE", configFile)
517-
ctx = env.Set(ctx, "DATABRICKS_CONFIG_PROFILE", "missing")
518517
cmd := newTestCmd(ctx)
519518

520519
cfg, resolveErr := resolveConfig(cmd)

0 commit comments

Comments
 (0)