Skip to content

Commit 2161509

Browse files
committed
Add regression test for bundle workspace.profile vs default_profile
When a bundle declares workspace.profile but no workspace.host and the user has [__settings__].default_profile set, the bundle's pinned profile must win. configureProfile's guard (Workspace.Profile == "") covers this case but had no test — verified by temporarily removing the guard, which flipped the asserted profile from PROFILE-2 to PROFILE-1. Co-authored-by: Isaac
1 parent c793668 commit 2161509

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

cmd/root/bundle_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,35 @@ 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+
297326
func TestBundleConfigureWithDefaultProfile_BundleHostWins(t *testing.T) {
298327
testutil.CleanupEnvironment(t)
299328
// PROFILE-1 points at https://a.test, but the bundle pins https://b.test.

0 commit comments

Comments
 (0)