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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions acceptance/cmd/api/debug/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

=== GET with --json

>>> [CLI] api get /api/2.0/test/echo --json {"id": 7} --debug
HH:MM:SS Debug: GET /api/2.0/test/echo?id=7
< HTTP/1.1 200 OK
< {
< "ok": true
< } pid=PID sdk=true
{
"ok": true
}

=== POST with --json

>>> [CLI] api post /api/2.0/test/echo --json {"id": 7} --debug
HH:MM:SS Debug: POST /api/2.0/test/echo
> {
> "id": 7
> }
< HTTP/1.1 200 OK
< {
< "ok": true
< } pid=PID sdk=true
{
"ok": true
}

=== Error response
HH:MM:SS Debug: GET /api/2.0/test/err404
< HTTP/1.1 404 Not Found
< {
< "error_code": "RESOURCE_DOES_NOT_EXIST",
< "message": "Not found"
< } pid=PID sdk=true
HH:MM:SS Debug: non-retriable error: Not found pid=PID sdk=true
Error: Not found
16 changes: 16 additions & 0 deletions acceptance/cmd/api/debug/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# What --debug prints for a request: the outgoing request and the response,
# including bodies. The lines around the dump are moved to the test log (see
# test.toml).

# Warm the host-metadata cache so the /.well-known/databricks-config exchange
# does not show up in the first case only.
MSYS_NO_PATHCONV=1 $CLI api get /api/2.0/test/echo > /dev/null

title "GET with --json"
MSYS_NO_PATHCONV=1 trace $CLI api get /api/2.0/test/echo --json '{"id": 7}' --debug 2>&1

title "POST with --json"
MSYS_NO_PATHCONV=1 trace $CLI api post /api/2.0/test/echo --json '{"id": 7}' --debug 2>&1

title "Error response"
MSYS_NO_PATHCONV=1 musterr $CLI api get /api/2.0/test/err404 --debug 2>&1
22 changes: 22 additions & 0 deletions acceptance/cmd/api/debug/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Only the request and response dump is about `databricks api`; the lines the
# CLI root and the SDK log around it (start/completed, local cache, resolved
# config, telemetry) are moved to the test log so an SDK bump that rewords them
# does not fail this test.
SuppressLines.debug_cli_lifecycle = '^HH:MM:SS Info: (start|completed execution|failed execution) '
SuppressLines.debug_local_cache = '^HH:MM:SS Debug: \[Local Cache\] '
SuppressLines.debug_resolved_config = '^HH:MM:SS Debug: Resolved \w+ from '
SuppressLines.debug_telemetry = '^HH:MM:SS Debug: no telemetry logs to upload'

# --debug output carries the process id, wall-clock timestamps and the
# host-metadata cache key, which hashes the test server URL (random port).
[[Repls]]
Old = "pid=[0-9]+"
New = "pid=PID"

[[Repls]]
Old = "(?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]"
New = "HH:MM:SS"

[[Repls]]
Old = "[0-9a-f]{64}"
New = "[SHA256_HASH]"
65 changes: 65 additions & 0 deletions acceptance/cmd/api/errors/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

=== 400 with a standard error body
Error: Cluster abc does not exist

Exit code: 1

=== 403 with a plain-text body
Error: Forbidden

Exit code: 1

=== 404 with a standard error body
Error: Not found

Exit code: 1

=== 409 on a POST
Error: Branch exists

Exit code: 1

=== 500 with an HTML body is not retried
Error: <html><body>Internal Server Error</body></html>

Exit code: 1

>>> print_requests.py --get //test/err500 --del-field headers
{
"method": "GET",
"path": "/api/2.0/test/err500"
}

=== 429 is retried

>>> [CLI] api get /api/2.0/test/echo
{
"ok": true
}

>>> print_requests.py --get //test/echo --del-field headers
{
"method": "GET",
"path": "/api/2.0/test/echo"
}
{
"method": "GET",
"path": "/api/2.0/test/echo"
}

=== 503 is retried

>>> [CLI] api get /api/2.0/test/echo
{
"ok": true
}

>>> print_requests.py --get //test/echo --del-field headers
{
"method": "GET",
"path": "/api/2.0/test/echo"
}
{
"method": "GET",
"path": "/api/2.0/test/echo"
}
32 changes: 32 additions & 0 deletions acceptance/cmd/api/errors/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# How HTTP error responses are rendered, their exit codes, and which are retried.

title "400 with a standard error body"
MSYS_NO_PATHCONV=1 musterr $CLI api get /api/2.0/test/err400
printf '\nExit code: %s\n' "$MUSTERR_EXIT_CODE"

title "403 with a plain-text body"
MSYS_NO_PATHCONV=1 musterr $CLI api get /api/2.0/test/err403
printf '\nExit code: %s\n' "$MUSTERR_EXIT_CODE"

title "404 with a standard error body"
MSYS_NO_PATHCONV=1 musterr $CLI api get /api/2.0/test/err404
printf '\nExit code: %s\n' "$MUSTERR_EXIT_CODE"

title "409 on a POST"
MSYS_NO_PATHCONV=1 musterr $CLI api post /api/2.0/test/err409 --json '{"spec": {}}'
printf '\nExit code: %s\n' "$MUSTERR_EXIT_CODE"

title "500 with an HTML body is not retried"
MSYS_NO_PATHCONV=1 musterr $CLI api get /api/2.0/test/err500
printf '\nExit code: %s\n' "$MUSTERR_EXIT_CODE"
trace print_requests.py --get //test/err500 --del-field headers

title "429 is retried"
fault.py "GET /api/2.0/test/echo" 429 0 1
MSYS_NO_PATHCONV=1 trace $CLI api get /api/2.0/test/echo
trace print_requests.py --get //test/echo --del-field headers

title "503 is retried"
fault.py "GET /api/2.0/test/echo" 503 0 1
MSYS_NO_PATHCONV=1 trace $CLI api get /api/2.0/test/echo
trace print_requests.py --get //test/echo --del-field headers
23 changes: 23 additions & 0 deletions acceptance/cmd/api/errors/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Error responses in the shapes the platform returns them; the 404 is shared
# with the debug test and lives in the parent test.toml.
[[Server]]
Pattern = "GET /api/2.0/test/err400"
Response.StatusCode = 400
Response.Body = '{"error_code": "INVALID_PARAMETER_VALUE", "message": "Cluster abc does not exist", "details": [{"@type": "type.googleapis.com/google.rpc.RequestInfo", "request_id": "req-1", "serving_data": ""}]}'
Response.Headers = { "Content-Type" = ["application/json"] }

[[Server]]
Pattern = "GET /api/2.0/test/err403"
Response.StatusCode = 403
Response.Body = 'Forbidden'

[[Server]]
Pattern = "GET /api/2.0/test/err500"
Response.StatusCode = 500
Response.Body = '<html><body>Internal Server Error</body></html>'

[[Server]]
Pattern = "POST /api/2.0/test/err409"
Response.StatusCode = 409
Response.Body = '{"error_code": "RESOURCE_CONFLICT", "message": "Branch exists"}'
Response.Headers = { "Content-Type" = ["application/json"] }
78 changes: 78 additions & 0 deletions acceptance/cmd/api/flags/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@

=== --account and --workspace-id are mutually exclusive
Error: --account and --workspace-id are mutually exclusive

=== --workspace-id requires a value
Error: --workspace-id requires a value; use --account to scope this call to the account API

=== PATH is required
Error: accepts 1 arg(s), received 0

Usage:
databricks api get PATH [flags]

Flags:
--account[=true|false] Treat this call as account-scoped (skip the workspace routing identifier). Mutually exclusive with --workspace-id.
-h, --help[=true|false] help for get
--json JSON either inline JSON string or @path/to/file.json with request body (default JSON (0 bytes))
--workspace-id string Override the workspace routing identifier on this call. Mutually exclusive with --account.

Global Flags:
--debug[=true|false] enable debug logging
-o, --output type output type: text or json (default text)
-p, --profile string ~/.databrickscfg profile
-t, --target string bundle target to use (if applicable)


=== An unknown method prints the help and succeeds

>>> [CLI] api options /api/2.0/test/echo
Perform Databricks API call

Usage:
databricks api [command]

Available Commands:
delete Perform DELETE request
get Perform GET request
head Perform HEAD request
patch Perform PATCH request
post Perform POST request
put Perform PUT request

Flags:
-h, --help[=true|false] help for api

Global Flags:
--debug[=true|false] enable debug logging
-o, --output type output type: text or json (default text)
-p, --profile string ~/.databrickscfg profile
-t, --target string bundle target to use (if applicable)

Use "databricks api [command] --help" for more information about a command.

=== curl-style flags are not accepted
Error: unknown shorthand flag: 'H' in -H
Error: unknown flag: --data
Error: unknown flag: --query
Error: unknown shorthand flag: 'i' in -i

=== Help

>>> [CLI] api get --help
Perform GET request

Usage:
databricks api get PATH [flags]

Flags:
--account[=true|false] Treat this call as account-scoped (skip the workspace routing identifier). Mutually exclusive with --workspace-id.
-h, --help[=true|false] help for get
--json JSON either inline JSON string or @path/to/file.json with request body (default JSON (0 bytes))
--workspace-id string Override the workspace routing identifier on this call. Mutually exclusive with --account.

Global Flags:
--debug[=true|false] enable debug logging
-o, --output type output type: text or json (default text)
-p, --profile string ~/.databrickscfg profile
-t, --target string bundle target to use (if applicable)
23 changes: 23 additions & 0 deletions acceptance/cmd/api/flags/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Flag validation and the flags that do not exist (curl-style flags).

title "--account and --workspace-id are mutually exclusive"
MSYS_NO_PATHCONV=1 musterr $CLI api get /api/2.0/test/echo --account --workspace-id 1

title "--workspace-id requires a value"
MSYS_NO_PATHCONV=1 musterr $CLI api get /api/2.0/test/echo --workspace-id ""

title "PATH is required"
musterr $CLI api get

title "An unknown method prints the help and succeeds"
MSYS_NO_PATHCONV=1 trace $CLI api options /api/2.0/test/echo

# Only the first line; the rest is the usage text pinned under "Help".
title "curl-style flags are not accepted"
MSYS_NO_PATHCONV=1 musterr $CLI api get /api/2.0/test/echo -H "X-Foo: bar" 2>&1 | head -n 1
MSYS_NO_PATHCONV=1 musterr $CLI api post /api/2.0/test/echo --data '{"a": 1}' 2>&1 | head -n 1
MSYS_NO_PATHCONV=1 musterr $CLI api get /api/2.0/test/echo --query a=b 2>&1 | head -n 1
MSYS_NO_PATHCONV=1 musterr $CLI api get /api/2.0/test/echo -i 2>&1 | head -n 1

title "Help"
trace $CLI api get --help
1 change: 1 addition & 0 deletions acceptance/cmd/api/json/body.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name": "from-file", "tags": ["x", "y"], "nested": {"k": true}}
Loading
Loading