Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
27 changes: 25 additions & 2 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,15 @@ func runTest(t *testing.T,
tmpDir = t.TempDir()
}

// Harness-written output files (output.txt, out.requests.txt) live outside the
// test dir so the bundle sync doesn't upload them as bundle sources. They are
// written here during the run and copied into tmpDir afterwards for comparison.
// Otherwise these continuously-rewritten files perturb the deploy "Files: N" count.
// Register this repl before [TEST_TMP_DIR] so it wins: outputDir is a sibling of
// tmpDir, so the [TEST_TMP_DIR]_PARENT repl would otherwise match it first.
outputDir := t.TempDir()
repls.SetPath(outputDir, "[OUTPUT_DIR]")

repls.SetPathWithParents(tmpDir, "[TEST_TMP_DIR]")

scriptContents := readMergedScriptContents(t, dir)
Expand Down Expand Up @@ -871,7 +880,7 @@ func runTest(t *testing.T,
args := []string{"bash", "-euo", "pipefail", EntryPointScript}
cmd := exec.CommandContext(ctx, args[0], args[1:]...)

cfg, user := internal.PrepareServerAndClient(t, config, LogRequests, tmpDir, testEnv)
cfg, user := internal.PrepareServerAndClient(t, config, LogRequests, outputDir, testEnv)
testdiff.PrepareReplacementsUser(t, &repls, user)
testdiff.PrepareReplacementsWorkspaceConfig(t, &repls, cfg)

Expand All @@ -888,6 +897,9 @@ func runTest(t *testing.T,
cmd.Env = append(cmd.Env, "DATABRICKS_RATE_LIMIT="+rateLimit)
cmd.Env = append(cmd.Env, "UNIQUE_NAME="+uniqueName)
cmd.Env = append(cmd.Env, "TEST_TMP_DIR="+tmpDir)
// Forward slashes: scripts pass $OUT_REQUESTS straight to bash tools, and a
// backslash Windows path would be mangled inside double quotes in Git Bash.
cmd.Env = append(cmd.Env, "OUT_REQUESTS="+filepath.ToSlash(filepath.Join(outputDir, "out.requests.txt")))

replsPath := filepath.Join(t.TempDir(), ReplsEnvVar)
cmd.Env = append(cmd.Env, ReplsEnvVar+"="+replsPath)
Expand Down Expand Up @@ -1001,7 +1013,7 @@ func runTest(t *testing.T,
}
cmd.Dir = tmpDir

outputPath := filepath.Join(tmpDir, "output.txt")
outputPath := filepath.Join(outputDir, "output.txt")
out, err := os.Create(outputPath)
require.NoError(t, err)
defer out.Close()
Expand All @@ -1022,8 +1034,19 @@ func runTest(t *testing.T,

pathFilter := preparePathFilter(config, customEnv)

// output.txt lives in outputDir, not tmpDir, so the bundle sync never uploads it;
// compare it from there. Every run produces it, so compare it explicitly rather
// than relying on it turning up in the tmpDir scan below. out.requests.txt also
// stays in outputDir and is never compared: tests assert on recorded requests
// through print_requests.py, not by committing the raw recording.
doComparison(t, repls, dir, outputDir, "output.txt", &printedRepls)

// Compare expected outputs
for relPath := range outputs {
if relPath == "output.txt" {
// Handled above: it is produced in outputDir, not tmpDir.
continue
}
if shouldSkip(pathFilter, relPath) {
continue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Deploying project...
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
Created apps.myapp
Files: 5 uploaded, 0 deleted
Files: 4 uploaded, 0 deleted
Resources: 1 created, 0 changed, 0 deleted, 0 unchanged
✓ Getting the status of the app myapp
✓ App is in UNAVAILABLE state
Expand Down
2 changes: 1 addition & 1 deletion acceptance/apps/deploy/bundle-no-args/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Deploying project...
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
Created apps.myapp
Files: 5 uploaded, 0 deleted
Files: 4 uploaded, 0 deleted
Resources: 1 created, 0 changed, 0 deleted, 0 unchanged
✓ Getting the status of the app myapp
✓ App is in UNAVAILABLE state
Expand Down
9 changes: 0 additions & 9 deletions acceptance/apps/deploy/bundle-with-appname/out.requests.txt

This file was deleted.

7 changes: 7 additions & 0 deletions acceptance/apps/deploy/bundle-with-appname/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@
"state": "PENDING"
}
}

>>> print_requests.py //apps
{
"method": "POST",
"path": "/api/2.0/apps/test-app/deployments",
"body": {}
}
2 changes: 2 additions & 0 deletions acceptance/apps/deploy/bundle-with-appname/script
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Test: apps deploy with APP_NAME in a bundle directory
# Expected: Falls back to API deploy (ignores bundle, no validation)
trace $CLI apps deploy test-app --no-wait

trace print_requests.py //apps

This file was deleted.

7 changes: 7 additions & 0 deletions acceptance/apps/deploy/no-bundle-with-appname/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@
"state": "PENDING"
}
}

>>> print_requests.py //apps
{
"method": "POST",
"path": "/api/2.0/apps/test-app/deployments",
"body": {}
}
2 changes: 2 additions & 0 deletions acceptance/apps/deploy/no-bundle-with-appname/script
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Test: apps deploy with APP_NAME but without databricks.yml
# Expected: Normal API deploy using apps deploy API
trace $CLI apps deploy test-app --no-wait

trace print_requests.py //apps
21 changes: 0 additions & 21 deletions acceptance/auth/credentials/basic/out.requests.txt

This file was deleted.

23 changes: 23 additions & 0 deletions acceptance/auth/credentials/basic/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,26 @@
"id": "[USERID]",
"userName": "[USERNAME]"
}

>>> print_requests.py --get //
{
"headers": {
"User-Agent": [
"cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"
]
},
"method": "GET",
"path": "/.well-known/databricks-config"
}
{
"headers": {
"Authorization": [
"Basic [ENCODED_AUTH]"
],
"User-Agent": [
"cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] interactive/none auth/basic"
]
},
"method": "GET",
"path": "/api/2.0/preview/scim/v2/Me"
}
2 changes: 2 additions & 0 deletions acceptance/auth/credentials/basic/script
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export DATABRICKS_USERNAME=username
export DATABRICKS_PASSWORD=password

$CLI current-user me

trace print_requests.py --get //
43 changes: 0 additions & 43 deletions acceptance/auth/credentials/oauth/out.requests.txt

This file was deleted.

45 changes: 45 additions & 0 deletions acceptance/auth/credentials/oauth/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,48 @@
"id": "[USERID]",
"userName": "[USERNAME]"
}

>>> print_requests.py --get //
{
"headers": {
"User-Agent": [
"cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"
]
},
"method": "GET",
"path": "/.well-known/databricks-config"
}
{
"headers": {
"User-Agent": [
"cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"
]
},
"method": "GET",
"path": "/oidc/.well-known/oauth-authorization-server"
}
{
"headers": {
"Authorization": [
"Basic [ENCODED_AUTH]"
],
"User-Agent": [
"cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"
]
},
"method": "POST",
"path": "/oidc/v1/token",
"raw_body": "grant_type=client_credentials&scope=all-apis"
}
{
"headers": {
"Authorization": [
"Bearer oauth-token"
],
"User-Agent": [
"cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] interactive/none auth/oauth-m2m"
]
},
"method": "GET",
"path": "/api/2.0/preview/scim/v2/Me"
}
2 changes: 2 additions & 0 deletions acceptance/auth/credentials/oauth/script
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export DATABRICKS_CLIENT_ID=client_id
export DATABRICKS_CLIENT_SECRET=client_secret

$CLI current-user me

trace print_requests.py --get //
21 changes: 0 additions & 21 deletions acceptance/auth/credentials/pat/out.requests.txt

This file was deleted.

23 changes: 23 additions & 0 deletions acceptance/auth/credentials/pat/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,26 @@
"id": "[USERID]",
"userName": "[USERNAME]"
}

>>> print_requests.py --get //
{
"headers": {
"User-Agent": [
"cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"
]
},
"method": "GET",
"path": "/.well-known/databricks-config"
}
{
"headers": {
"Authorization": [
"Bearer dapi1234"
],
"User-Agent": [
"cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] interactive/none auth/pat"
]
},
"method": "GET",
"path": "/api/2.0/preview/scim/v2/Me"
}
2 changes: 2 additions & 0 deletions acceptance/auth/credentials/pat/script
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export DATABRICKS_TOKEN=dapi1234

$CLI current-user me

trace print_requests.py --get //
5 changes: 3 additions & 2 deletions acceptance/bin/extract_command_exec_id.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python3
import json
import os
import re
from pathlib import Path


def extract_cmd_exec_id():
requests_file = Path("out.requests.txt")
requests_file = Path(os.environ["OUT_REQUESTS"])

# Read JSON objects one at a time and find the first one with a cmd-exec-id
# in the User-Agent header. Some requests (e.g. .well-known/databricks-config)
Expand All @@ -31,7 +32,7 @@ def extract_cmd_exec_id():
if match:
return match.group(1)

raise SystemExit("No command execution ID found in any request in out.requests.txt")
raise SystemExit(f"No command execution ID found in any request in {requests_file}")


if __name__ == "__main__":
Expand Down
9 changes: 5 additions & 4 deletions acceptance/bin/print_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,20 @@ def main():
"bodies, so a test asserts the same requests whether or not deployment history "
"recording is on. Shorthand for the --del-body fields it implies.",
)
parser.add_argument("--fname", default="out.requests.txt")
parser.add_argument("--fname", default=os.environ["OUT_REQUESTS"])
args = parser.parse_args()

del_body_fields = [field for group in args.del_body for field in group.split(",")]
if args.nostamp:
del_body_fields += STAMP_FIELDS
del_fields = [field for group in args.del_field for field in group.split(",")]

fname = Path(args.fname)
test_tmp_dir = os.environ.get("TEST_TMP_DIR")
if test_tmp_dir:
requests_file = Path(test_tmp_dir) / args.fname
if test_tmp_dir and not fname.is_absolute():
requests_file = Path(test_tmp_dir) / fname
else:
requests_file = Path(args.fname)
requests_file = fname

if not requests_file.exists():
sys.exit(f"File {requests_file.as_posix()} not found")
Expand Down
Loading
Loading