Skip to content

Commit b34db38

Browse files
committed
Make acceptance sethome export an absolute HOME (cross-platform)
sethome exported HOME (and USERPROFILE) as the relative path the caller passed in (typically "./home"). The SDK expands `~/.databrickscfg` against $HOME at lookup time, so the moment a test cd's into a child directory the cfg "disappears": helpers like databrickscfg.GetConfiguredDefaultProfile silently return "" because the relative path no longer points at a real file. That made it easy to write tests that look like they exercise default_profile resolution but actually only succeed because the cfg lookup short-circuits. Resolve $1 to an absolute path with `cd && pwd` before exporting. On Git Bash (MSYS) plain `pwd` returns Unix-style /c/... paths that the native Windows Go binary can't open, so use `pwd -W` to get the mixed C:/... form. Use the same form for both HOME and USERPROFILE so tests like cmd/completion (which registers `$HOME` as the `[HOME]` replacement) match the CLI's USERPROFILE-derived output on Windows. Regenerate the four affected outputs. Co-authored-by: Isaac
1 parent 9f3ddf5 commit b34db38

6 files changed

Lines changed: 35 additions & 20 deletions

File tree

acceptance/auth/bundle_default_profile/output.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ Exit code: 1
2323
=== Bundle with workspace.host: default_profile is NOT applied
2424

2525
>>> errcode [CLI] bundle validate -o json
26-
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: host=[DATABRICKS_URL], workspace_id=[NUMID], databricks_cli_path=[CLI]. Env: DATABRICKS_CLI_PATH
27-
28-
29-
Exit code: 1
3026
{
3127
"host": "[DATABRICKS_URL]",
3228
"profile": null
@@ -35,7 +31,7 @@ Exit code: 1
3531
=== Bundle with workspace.profile: pinned profile wins over default_profile
3632

3733
>>> 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
34+
Error: Get "https://other.test/api/2.0/preview/scim/v2/Me": (redacted)
3935

4036

4137
Exit code: 1

acceptance/cmd/auth/describe/u2m-plaintext-config/output.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
>>> [CLI] auth describe --profile u2m-profile
33
Warn: [hostmetadata] failed to fetch host metadata for https://u2m-profile.databricks.test, will skip for 1m0s
44
Unable to authenticate: error getting token: cache: token not found
5-
Token storage: plaintext, ~/.databricks/token-cache.json (from auth_storage in [__settings__] section of home/.databrickscfg)
5+
Token storage: plaintext, ~/.databricks/token-cache.json (from auth_storage in [__settings__] section of [TEST_TMP_DIR]/home/.databrickscfg)
66
-----
77
Current configuration:
8-
✓ host: https://u2m-profile.databricks.test (from ./home/.databrickscfg config file)
8+
✓ host: https://u2m-profile.databricks.test (from [TEST_TMP_DIR]/home/.databrickscfg config file)
99
✓ profile: u2m-profile (from --profile flag)
1010
✓ databricks_cli_path: [CLI]
11-
✓ auth_type: databricks-cli (from ./home/.databrickscfg config file)
11+
✓ auth_type: databricks-cli (from [TEST_TMP_DIR]/home/.databrickscfg config file)
1212
✓ rate_limit: [NUMID] (from DATABRICKS_RATE_LIMIT environment variable)

acceptance/cmd/auth/describe/u2m-plaintext-default/output.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Unable to authenticate: error getting token: cache: token not found
55
Token storage: plaintext, ~/.databricks/token-cache.json (from default)
66
-----
77
Current configuration:
8-
✓ host: https://u2m-profile.databricks.test (from ./home/.databrickscfg config file)
8+
✓ host: https://u2m-profile.databricks.test (from [TEST_TMP_DIR]/home/.databrickscfg config file)
99
✓ profile: u2m-profile (from --profile flag)
1010
✓ databricks_cli_path: [CLI]
11-
✓ auth_type: databricks-cli (from ./home/.databrickscfg config file)
11+
✓ auth_type: databricks-cli (from [TEST_TMP_DIR]/home/.databrickscfg config file)
1212
✓ rate_limit: [NUMID] (from DATABRICKS_RATE_LIMIT environment variable)

acceptance/cmd/auth/describe/u2m-plaintext-env/output.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Unable to authenticate: error getting token: cache: token not found
55
Token storage: plaintext, ~/.databricks/token-cache.json (from DATABRICKS_AUTH_STORAGE environment variable)
66
-----
77
Current configuration:
8-
✓ host: https://u2m-profile.databricks.test (from ./home/.databrickscfg config file)
8+
✓ host: https://u2m-profile.databricks.test (from [TEST_TMP_DIR]/home/.databrickscfg config file)
99
✓ profile: u2m-profile (from --profile flag)
1010
✓ databricks_cli_path: [CLI]
11-
✓ auth_type: databricks-cli (from ./home/.databrickscfg config file)
11+
✓ auth_type: databricks-cli (from [TEST_TMP_DIR]/home/.databrickscfg config file)
1212
✓ rate_limit: [NUMID] (from DATABRICKS_RATE_LIMIT environment variable)

acceptance/cmd/completion/output.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11

22
>>> [CLI] completion install --shell zsh --auto-approve
33
Databricks CLI completions installed for zsh.
4-
Restart your shell or run 'source home/.zshrc' to activate.
4+
Restart your shell or run 'source [HOME]/.zshrc' to activate.
55

66
Warning: zsh completions require the completion system to be initialized.
7-
Add the following to your home/.zshrc:
7+
Add the following to your [HOME]/.zshrc:
88
autoload -U compinit && compinit
99

1010
>>> [CLI] completion status --shell zsh
1111
Shell: zsh
12-
File: home/.zshrc
12+
File: [HOME]/.zshrc
1313
Status: installed
1414

1515
Warning: zsh completions require the completion system to be initialized.
16-
Add the following to your home/.zshrc:
16+
Add the following to your [HOME]/.zshrc:
1717
autoload -U compinit && compinit
1818

1919
>>> [CLI] completion install --shell zsh --auto-approve
20-
Databricks CLI completions are already installed for zsh in home/.zshrc.
20+
Databricks CLI completions are already installed for zsh in [HOME]/.zshrc.
2121

2222
Warning: zsh completions require the completion system to be initialized.
23-
Add the following to your home/.zshrc:
23+
Add the following to your [HOME]/.zshrc:
2424
autoload -U compinit && compinit
2525

2626
>>> [CLI] completion uninstall --shell zsh --auto-approve
27-
Databricks CLI completions removed for zsh from home/.zshrc.
27+
Databricks CLI completions removed for zsh from [HOME]/.zshrc.
2828

2929
>>> [CLI] completion status --shell zsh
3030
Shell: zsh
31-
File: home/.zshrc
31+
File: [HOME]/.zshrc
3232
Status: not installed
3333
# bash completion V2 for databricks -*- shell-script -*-
3434
#compdef databricks

acceptance/script.prepare

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,25 @@ sethome() {
101101
local home="$1"
102102
mkdir -p "$home"
103103

104+
# Resolve to an absolute path so HOME (and USERPROFILE) keep pointing at
105+
# the same directory after the test cd's elsewhere. The SDK expands
106+
# `~/.databrickscfg` against $HOME at lookup time; with a relative path
107+
# the cfg silently disappears once the cwd changes, and helpers like
108+
# databrickscfg.GetConfiguredDefaultProfile return "" instead of
109+
# erroring.
110+
#
111+
# On Git Bash (MSYS), plain `pwd` returns Unix-style /c/... paths that
112+
# the native Windows Go binary can't open; `pwd -W` returns the mixed
113+
# C:/... form instead. Use the same form for both HOME and USERPROFILE
114+
# so tests that compare a `$HOME`-based placeholder against the CLI's
115+
# `os.UserHomeDir()` output (which reads USERPROFILE on Windows) find
116+
# a match.
117+
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then
118+
home="$(cd "$home" && pwd -W)"
119+
else
120+
home="$(cd "$home" && pwd)"
121+
fi
122+
104123
# For macOS and Linux, use HOME.
105124
export HOME="$home"
106125

0 commit comments

Comments
 (0)