Skip to content

Commit 8351385

Browse files
committed
Move workspace.profile regression test from unit to acceptance
The previous unit test for the Workspace.Profile == "" guard sat alongside other configureProfile unit tests, but per .agent/rules/testing.md, cmd/... behavior is a strong candidate for acceptance tests, and the existing acceptance/auth/bundle_default_profile/ already covers the related host-empty guard end-to-end. Extending it keeps the related cases together. The new sub-case spawns a child bundle directory with workspace.profile pinned and asserts the bundle's profile (not [__settings__].default_profile) is what gets used. Co-authored-by: Isaac
1 parent 2161509 commit 8351385

4 files changed

Lines changed: 28 additions & 29 deletions

File tree

acceptance/auth/bundle_default_profile/output.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,15 @@ Exit code: 1
3131
"host": "[DATABRICKS_URL]",
3232
"profile": null
3333
}
34+
35+
=== Bundle with workspace.profile: pinned profile wins over default_profile
36+
37+
>>> errcode [CLI] bundle validate -o json
38+
Error: failed during request visitor: default auth: cannot configure default credentials, please check https://docs.databricks.com/en/dev-tools/auth.html#databricks-client-unified-authentication to configure credentials for your preferred authentication method. Config: profile=other, databricks_cli_path=[CLI]. Env: DATABRICKS_CLI_PATH
39+
40+
41+
Exit code: 1
42+
{
43+
"host": null,
44+
"profile": "other"
45+
}

acceptance/auth/bundle_default_profile/script

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,18 @@ EOF
4141

4242
title "Bundle with workspace.host: default_profile is NOT applied\n"
4343
(cd ./bundle-with-host && trace errcode $CLI bundle validate -o json | jq '{host: .workspace.host, profile: .workspace.profile}')
44+
45+
# Switch to a bundle that pins workspace.profile but no host. The pinned
46+
# profile must win over default_profile — configureProfile's guard skips
47+
# default_profile when workspace.profile is already set.
48+
mkdir -p ./bundle-with-profile
49+
cat > ./bundle-with-profile/databricks.yml <<EOF
50+
bundle:
51+
name: bundle-with-profile
52+
53+
workspace:
54+
profile: other
55+
EOF
56+
57+
title "Bundle with workspace.profile: pinned profile wins over default_profile\n"
58+
(cd ./bundle-with-profile && trace errcode $CLI bundle validate -o json | jq '{host: .workspace.host, profile: .workspace.profile}')

acceptance/auth/bundle_default_profile/test.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Ignore = [
22
"home",
33
".databricks",
44
"bundle-with-host",
5+
"bundle-with-profile",
56
]
67

78
# Negative case: -p other tries to reach a non-existing host. Redact the

cmd/root/bundle_test.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -294,35 +294,6 @@ func TestBundleConfigureWithDefaultProfile_EnvVarOverrides(t *testing.T) {
294294
assert.Equal(t, "PROFILE-2", cmdctx.ConfigUsed(cmd.Context()).Profile)
295295
}
296296

297-
func TestBundleConfigureWithDefaultProfile_BundleProfileWins(t *testing.T) {
298-
testutil.CleanupEnvironment(t)
299-
// The bundle pins workspace.profile: PROFILE-2 but no host. cfg has
300-
// default_profile = PROFILE-1. The bundle's pinned profile must win —
301-
// configureProfile's guard skips default_profile when workspace.profile
302-
// is already set. Inline the bundle write because setupWithProfile would
303-
// overwrite the cfg fixture.
304-
setupDatabricksCfgWithDefault(t, "PROFILE-1")
305-
306-
rootPath := t.TempDir()
307-
t.Chdir(rootPath)
308-
309-
contents := `workspace:
310-
profile: "PROFILE-2"
311-
`
312-
err := os.WriteFile(filepath.Join(rootPath, "databricks.yml"), []byte(contents), 0o644)
313-
require.NoError(t, err)
314-
315-
cmd := emptyCommand(t)
316-
ctx := logdiag.InitContext(cmd.Context())
317-
logdiag.SetCollect(ctx, true)
318-
cmd.SetContext(ctx)
319-
_ = MustConfigureBundle(cmd)
320-
diags := logdiag.FlushCollected(ctx)
321-
require.Empty(t, diags)
322-
assert.Equal(t, "https://b.test", cmdctx.ConfigUsed(cmd.Context()).Host)
323-
assert.Equal(t, "PROFILE-2", cmdctx.ConfigUsed(cmd.Context()).Profile)
324-
}
325-
326297
func TestBundleConfigureWithDefaultProfile_BundleHostWins(t *testing.T) {
327298
testutil.CleanupEnvironment(t)
328299
// PROFILE-1 points at https://a.test, but the bundle pins https://b.test.

0 commit comments

Comments
 (0)