diff --git a/acceptance/cmd/api/account-flag/out.test.toml b/acceptance/cmd/api/debug/out.test.toml similarity index 100% rename from acceptance/cmd/api/account-flag/out.test.toml rename to acceptance/cmd/api/debug/out.test.toml diff --git a/acceptance/cmd/api/debug/output.txt b/acceptance/cmd/api/debug/output.txt new file mode 100644 index 00000000000..8f822fb8785 --- /dev/null +++ b/acceptance/cmd/api/debug/output.txt @@ -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 diff --git a/acceptance/cmd/api/debug/script b/acceptance/cmd/api/debug/script new file mode 100644 index 00000000000..22245d11858 --- /dev/null +++ b/acceptance/cmd/api/debug/script @@ -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 diff --git a/acceptance/cmd/api/debug/test.toml b/acceptance/cmd/api/debug/test.toml new file mode 100644 index 00000000000..d6cc6b36f6e --- /dev/null +++ b/acceptance/cmd/api/debug/test.toml @@ -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]" diff --git a/acceptance/cmd/api/account-path/out.test.toml b/acceptance/cmd/api/errors/out.test.toml similarity index 100% rename from acceptance/cmd/api/account-path/out.test.toml rename to acceptance/cmd/api/errors/out.test.toml diff --git a/acceptance/cmd/api/errors/output.txt b/acceptance/cmd/api/errors/output.txt new file mode 100644 index 00000000000..4ddec16fad4 --- /dev/null +++ b/acceptance/cmd/api/errors/output.txt @@ -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:
Internal Server Error + +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" +} diff --git a/acceptance/cmd/api/errors/script b/acceptance/cmd/api/errors/script new file mode 100644 index 00000000000..62e938d2bbf --- /dev/null +++ b/acceptance/cmd/api/errors/script @@ -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 diff --git a/acceptance/cmd/api/errors/test.toml b/acceptance/cmd/api/errors/test.toml new file mode 100644 index 00000000000..2fed8b709b4 --- /dev/null +++ b/acceptance/cmd/api/errors/test.toml @@ -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 = 'Internal Server Error' + +[[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"] } diff --git a/acceptance/cmd/api/default-profile-vs-env/out.test.toml b/acceptance/cmd/api/flags/out.test.toml similarity index 100% rename from acceptance/cmd/api/default-profile-vs-env/out.test.toml rename to acceptance/cmd/api/flags/out.test.toml diff --git a/acceptance/cmd/api/flags/output.txt b/acceptance/cmd/api/flags/output.txt new file mode 100644 index 00000000000..94fa40749f7 --- /dev/null +++ b/acceptance/cmd/api/flags/output.txt @@ -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) diff --git a/acceptance/cmd/api/flags/script b/acceptance/cmd/api/flags/script new file mode 100644 index 00000000000..c7cfab225f7 --- /dev/null +++ b/acceptance/cmd/api/flags/script @@ -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 diff --git a/acceptance/cmd/api/json/body.json b/acceptance/cmd/api/json/body.json new file mode 100644 index 00000000000..a420e872ddf --- /dev/null +++ b/acceptance/cmd/api/json/body.json @@ -0,0 +1 @@ +{"name": "from-file", "tags": ["x", "y"], "nested": {"k": true}} diff --git a/acceptance/cmd/api/default-profile/out.test.toml b/acceptance/cmd/api/json/out.test.toml similarity index 100% rename from acceptance/cmd/api/default-profile/out.test.toml rename to acceptance/cmd/api/json/out.test.toml diff --git a/acceptance/cmd/api/json/output.txt b/acceptance/cmd/api/json/output.txt new file mode 100644 index 00000000000..c7eab12d29e --- /dev/null +++ b/acceptance/cmd/api/json/output.txt @@ -0,0 +1,130 @@ + +=== Accept: application/json is sent (the raw response target must not drop it) + +OK: Accept header present + +=== A literal 'null' --json sends no request body (not the bytes "null") + +>>> print_requests.py //test/req --del-field headers +{ + "method": "POST", + "path": "/api/2.0/test/req" +} + +=== Query parameters in the path and a --json body are both sent + +>>> print_requests.py //test/req --del-field headers +{ + "method": "POST", + "path": "/api/2.0/test/req", + "q": { + "foo": "bar", + "x": "1" + }, + "body": { + "hello": "world" + } +} + +=== Malformed --json is rejected client-side with a positioned error +Error: error decoding JSON at (inline):1:8: invalid character ',' looking for beginning of value + +=== --json @file is the body of a POST + +>>> [CLI] api post /api/2.0/test/echo --json @body.json +{ + "ok": true +} + +>>> print_requests.py //test/echo --del-field headers +{ + "method": "POST", + "path": "/api/2.0/test/echo", + "body": { + "name": "from-file", + "tags": [ + "x", + "y" + ], + "nested": { + "k": true + } + } +} + +=== --json @file on a GET is serialized into the query string, arrays and objects with Go's %v + +>>> [CLI] api get /api/2.0/test/echo --json @body.json +{ + "ok": true +} + +>>> print_requests.py --get //test/echo --del-field headers +{ + "method": "GET", + "path": "/api/2.0/test/echo", + "q": { + "name": "from-file", + "nested": "map[k:true]", + "tags": "[x y]" + } +} + +=== --json @- is not stdin; it is read as a file named '-' + +OK: '-' was opened as a file + +=== --json on a GET whose path already has a query string + +>>> [CLI] api get /api/2.0/test/echo?a=1 --json {"b": 2} +{ + "ok": true +} + +>>> print_requests.py --get //test/echo --del-field headers +{ + "method": "GET", + "path": "/api/2.0/test/echo", + "q": { + "a": "1?b=2" + } +} + +=== --json scalars on a GET: null is dropped, other zero values are kept + +>>> [CLI] api get /api/2.0/test/echo --json {"flag": true, "off": false, "n": 0, "empty": "", "none": null} +{ + "ok": true +} + +>>> print_requests.py --get //test/echo --del-field headers +{ + "method": "GET", + "path": "/api/2.0/test/echo", + "q": { + "empty": "", + "flag": "true", + "n": "0", + "off": "false" + } +} + +=== --json that is not an object is sent verbatim on a POST + +>>> [CLI] api post /api/2.0/test/echo --json [1, 2] +{ + "ok": true +} + +>>> print_requests.py //test/echo --del-field headers +{ + "method": "POST", + "path": "/api/2.0/test/echo", + "body": [ + 1, + 2 + ] +} + +=== --json that is not an object is rejected on a GET +Error: request marshal: unsupported query string data: []interface {}{"1", "2"} diff --git a/acceptance/cmd/api/json/script b/acceptance/cmd/api/json/script new file mode 100644 index 00000000000..16558bfad24 --- /dev/null +++ b/acceptance/cmd/api/json/script @@ -0,0 +1,45 @@ +# Behaviours of how `databricks api` builds the outgoing request. + +title "Accept: application/json is sent (the raw response target must not drop it)" +MSYS_NO_PATHCONV=1 $CLI api post /api/2.0/test/req --json '{"a": 1}' > /dev/null +print_requests.py //test/req | contains.py '"Accept"' '"application/json"' > /dev/null +printf '\n%s\n' "OK: Accept header present" + +title "A literal 'null' --json sends no request body (not the bytes \"null\")" +MSYS_NO_PATHCONV=1 $CLI api post /api/2.0/test/req --json 'null' > /dev/null +trace print_requests.py //test/req --del-field headers + +title "Query parameters in the path and a --json body are both sent" +MSYS_NO_PATHCONV=1 $CLI api post "/api/2.0/test/req?foo=bar&x=1" --json '{"hello": "world"}' > /dev/null +trace print_requests.py //test/req --del-field headers + +title "Malformed --json is rejected client-side with a positioned error" +MSYS_NO_PATHCONV=1 musterr $CLI api post /api/2.0/test/req --json '{"a": 1,}' + +title "--json @file is the body of a POST" +MSYS_NO_PATHCONV=1 trace $CLI api post /api/2.0/test/echo --json @body.json +trace print_requests.py //test/echo --del-field headers + +title "--json @file on a GET is serialized into the query string, arrays and objects with Go's %v" +MSYS_NO_PATHCONV=1 trace $CLI api get /api/2.0/test/echo --json @body.json +trace print_requests.py --get //test/echo --del-field headers + +title "--json @- is not stdin; it is read as a file named '-'" +echo '{"a": 1}' | MSYS_NO_PATHCONV=1 musterr $CLI api post /api/2.0/test/echo --json @- &> LOG.stdin +contains.py "open -" < LOG.stdin > /dev/null +printf '\n%s\n' "OK: '-' was opened as a file" + +title "--json on a GET whose path already has a query string" +MSYS_NO_PATHCONV=1 trace $CLI api get "/api/2.0/test/echo?a=1" --json '{"b": 2}' +trace print_requests.py --get //test/echo --del-field headers + +title "--json scalars on a GET: null is dropped, other zero values are kept" +MSYS_NO_PATHCONV=1 trace $CLI api get /api/2.0/test/echo --json '{"flag": true, "off": false, "n": 0, "empty": "", "none": null}' +trace print_requests.py --get //test/echo --del-field headers + +title "--json that is not an object is sent verbatim on a POST" +MSYS_NO_PATHCONV=1 trace $CLI api post /api/2.0/test/echo --json '[1, 2]' +trace print_requests.py //test/echo --del-field headers + +title "--json that is not an object is rejected on a GET" +MSYS_NO_PATHCONV=1 musterr $CLI api get /api/2.0/test/echo --json '[1, 2]' diff --git a/acceptance/cmd/api/request-handling/test.toml b/acceptance/cmd/api/json/test.toml similarity index 100% rename from acceptance/cmd/api/request-handling/test.toml rename to acceptance/cmd/api/json/test.toml diff --git a/acceptance/cmd/api/request-handling/out.test.toml b/acceptance/cmd/api/methods/out.test.toml similarity index 100% rename from acceptance/cmd/api/request-handling/out.test.toml rename to acceptance/cmd/api/methods/out.test.toml diff --git a/acceptance/cmd/api/methods/output.txt b/acceptance/cmd/api/methods/output.txt new file mode 100644 index 00000000000..9301bed1d24 --- /dev/null +++ b/acceptance/cmd/api/methods/output.txt @@ -0,0 +1,380 @@ + +=== get without --json + +>>> [CLI] api get /api/2.0/test/echo +{ + "ok": true +} + +>>> print_requests.py --get //test/echo +{ + "headers": { + "Accept": [ + "application/json" + ], + "Authorization": [ + "Bearer [DATABRICKS_TOKEN]" + ], + "Content-Type": [ + "application/json" + ], + "User-Agent": [ + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_get cmd-exec-id/[UUID][0] interactive/none auth/pat" + ], + "X-Databricks-Workspace-Id": [ + "[WORKSPACE_ID]" + ] + }, + "method": "GET", + "path": "/api/2.0/test/echo" +} + +=== get with --json + +>>> [CLI] api get /api/2.0/test/echo --json {"id": 7, "name": "a b"} +{ + "ok": true +} + +>>> print_requests.py --get //test/echo +{ + "headers": { + "Accept": [ + "application/json" + ], + "Authorization": [ + "Bearer [DATABRICKS_TOKEN]" + ], + "Content-Type": [ + "application/json" + ], + "User-Agent": [ + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_get cmd-exec-id/[UUID][1] interactive/none auth/pat" + ], + "X-Databricks-Workspace-Id": [ + "[WORKSPACE_ID]" + ] + }, + "method": "GET", + "path": "/api/2.0/test/echo", + "q": { + "id": "7", + "name": "a b" + } +} + +=== head without --json + +>>> [CLI] api head /api/2.0/test/echo +null + +>>> print_requests.py --get //test/echo +{ + "headers": { + "Accept": [ + "application/json" + ], + "Authorization": [ + "Bearer [DATABRICKS_TOKEN]" + ], + "Content-Type": [ + "application/json" + ], + "User-Agent": [ + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_head cmd-exec-id/[UUID][2] interactive/none auth/pat" + ], + "X-Databricks-Workspace-Id": [ + "[WORKSPACE_ID]" + ] + }, + "method": "HEAD", + "path": "/api/2.0/test/echo" +} + +=== head with --json + +>>> [CLI] api head /api/2.0/test/echo --json {"id": 7, "name": "a b"} +null + +>>> print_requests.py --get //test/echo +{ + "headers": { + "Accept": [ + "application/json" + ], + "Authorization": [ + "Bearer [DATABRICKS_TOKEN]" + ], + "Content-Type": [ + "application/json" + ], + "User-Agent": [ + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_head cmd-exec-id/[UUID][3] interactive/none auth/pat" + ], + "X-Databricks-Workspace-Id": [ + "[WORKSPACE_ID]" + ] + }, + "method": "HEAD", + "path": "/api/2.0/test/echo", + "q": { + "id": "7", + "name": "a b" + } +} + +=== post without --json + +>>> [CLI] api post /api/2.0/test/echo +{ + "ok": true +} + +>>> print_requests.py --get //test/echo +{ + "headers": { + "Accept": [ + "application/json" + ], + "Authorization": [ + "Bearer [DATABRICKS_TOKEN]" + ], + "Content-Type": [ + "application/json" + ], + "User-Agent": [ + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_post cmd-exec-id/[UUID][4] interactive/none auth/pat" + ], + "X-Databricks-Workspace-Id": [ + "[WORKSPACE_ID]" + ] + }, + "method": "POST", + "path": "/api/2.0/test/echo" +} + +=== post with --json + +>>> [CLI] api post /api/2.0/test/echo --json {"id": 7, "name": "a b"} +{ + "ok": true +} + +>>> print_requests.py --get //test/echo +{ + "headers": { + "Accept": [ + "application/json" + ], + "Authorization": [ + "Bearer [DATABRICKS_TOKEN]" + ], + "Content-Type": [ + "application/json" + ], + "User-Agent": [ + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_post cmd-exec-id/[UUID][5] interactive/none auth/pat" + ], + "X-Databricks-Workspace-Id": [ + "[WORKSPACE_ID]" + ] + }, + "method": "POST", + "path": "/api/2.0/test/echo", + "body": { + "id": 7, + "name": "a b" + } +} + +=== put without --json + +>>> [CLI] api put /api/2.0/test/echo +{ + "ok": true +} + +>>> print_requests.py --get //test/echo +{ + "headers": { + "Accept": [ + "application/json" + ], + "Authorization": [ + "Bearer [DATABRICKS_TOKEN]" + ], + "Content-Type": [ + "application/json" + ], + "User-Agent": [ + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_put cmd-exec-id/[UUID][6] interactive/none auth/pat" + ], + "X-Databricks-Workspace-Id": [ + "[WORKSPACE_ID]" + ] + }, + "method": "PUT", + "path": "/api/2.0/test/echo" +} + +=== put with --json + +>>> [CLI] api put /api/2.0/test/echo --json {"id": 7, "name": "a b"} +{ + "ok": true +} + +>>> print_requests.py --get //test/echo +{ + "headers": { + "Accept": [ + "application/json" + ], + "Authorization": [ + "Bearer [DATABRICKS_TOKEN]" + ], + "Content-Type": [ + "application/json" + ], + "User-Agent": [ + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_put cmd-exec-id/[UUID][7] interactive/none auth/pat" + ], + "X-Databricks-Workspace-Id": [ + "[WORKSPACE_ID]" + ] + }, + "method": "PUT", + "path": "/api/2.0/test/echo", + "body": { + "id": 7, + "name": "a b" + } +} + +=== patch without --json + +>>> [CLI] api patch /api/2.0/test/echo +{ + "ok": true +} + +>>> print_requests.py --get //test/echo +{ + "headers": { + "Accept": [ + "application/json" + ], + "Authorization": [ + "Bearer [DATABRICKS_TOKEN]" + ], + "Content-Type": [ + "application/json" + ], + "User-Agent": [ + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_patch cmd-exec-id/[UUID][8] interactive/none auth/pat" + ], + "X-Databricks-Workspace-Id": [ + "[WORKSPACE_ID]" + ] + }, + "method": "PATCH", + "path": "/api/2.0/test/echo" +} + +=== patch with --json + +>>> [CLI] api patch /api/2.0/test/echo --json {"id": 7, "name": "a b"} +{ + "ok": true +} + +>>> print_requests.py --get //test/echo +{ + "headers": { + "Accept": [ + "application/json" + ], + "Authorization": [ + "Bearer [DATABRICKS_TOKEN]" + ], + "Content-Type": [ + "application/json" + ], + "User-Agent": [ + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_patch cmd-exec-id/[UUID][9] interactive/none auth/pat" + ], + "X-Databricks-Workspace-Id": [ + "[WORKSPACE_ID]" + ] + }, + "method": "PATCH", + "path": "/api/2.0/test/echo", + "body": { + "id": 7, + "name": "a b" + } +} + +=== delete without --json + +>>> [CLI] api delete /api/2.0/test/echo +{ + "ok": true +} + +>>> print_requests.py --get //test/echo +{ + "headers": { + "Accept": [ + "application/json" + ], + "Authorization": [ + "Bearer [DATABRICKS_TOKEN]" + ], + "Content-Type": [ + "application/json" + ], + "User-Agent": [ + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_delete cmd-exec-id/[UUID][10] interactive/none auth/pat" + ], + "X-Databricks-Workspace-Id": [ + "[WORKSPACE_ID]" + ] + }, + "method": "DELETE", + "path": "/api/2.0/test/echo" +} + +=== delete with --json + +>>> [CLI] api delete /api/2.0/test/echo --json {"id": 7, "name": "a b"} +{ + "ok": true +} + +>>> print_requests.py --get //test/echo +{ + "headers": { + "Accept": [ + "application/json" + ], + "Authorization": [ + "Bearer [DATABRICKS_TOKEN]" + ], + "Content-Type": [ + "application/json" + ], + "User-Agent": [ + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_delete cmd-exec-id/[UUID][11] interactive/none auth/pat" + ], + "X-Databricks-Workspace-Id": [ + "[WORKSPACE_ID]" + ] + }, + "method": "DELETE", + "path": "/api/2.0/test/echo", + "q": { + "id": "7", + "name": "a b" + } +} diff --git a/acceptance/cmd/api/methods/script b/acceptance/cmd/api/methods/script new file mode 100644 index 00000000000..36c97cadd10 --- /dev/null +++ b/acceptance/cmd/api/methods/script @@ -0,0 +1,13 @@ +# One request per HTTP method, with and without --json. Pins where the JSON +# input goes (query string for GET, HEAD and DELETE; body otherwise) and which +# headers are sent. + +for method in get head post put patch delete; do + title "$method without --json" + MSYS_NO_PATHCONV=1 trace $CLI api $method /api/2.0/test/echo + trace print_requests.py --get //test/echo + + title "$method with --json" + MSYS_NO_PATHCONV=1 trace $CLI api $method /api/2.0/test/echo --json '{"id": 7, "name": "a b"}' + trace print_requests.py --get //test/echo +done diff --git a/acceptance/cmd/api/methods/test.toml b/acceptance/cmd/api/methods/test.toml new file mode 100644 index 00000000000..efda25e31ba --- /dev/null +++ b/acceptance/cmd/api/methods/test.toml @@ -0,0 +1,3 @@ +# Appended to the inherited list so the recorded requests show how the request +# is described, not only how it is authenticated and routed. +IncludeRequestHeaders = ["Accept", "Content-Type"] diff --git a/acceptance/cmd/api/default-profile-vs-env/home/.databrickscfg b/acceptance/cmd/api/profile-default-vs-env/home/.databrickscfg similarity index 100% rename from acceptance/cmd/api/default-profile-vs-env/home/.databrickscfg rename to acceptance/cmd/api/profile-default-vs-env/home/.databrickscfg diff --git a/acceptance/cmd/api/response-handling/out.test.toml b/acceptance/cmd/api/profile-default-vs-env/out.test.toml similarity index 100% rename from acceptance/cmd/api/response-handling/out.test.toml rename to acceptance/cmd/api/profile-default-vs-env/out.test.toml diff --git a/acceptance/cmd/api/default-profile-vs-env/output.txt b/acceptance/cmd/api/profile-default-vs-env/output.txt similarity index 100% rename from acceptance/cmd/api/default-profile-vs-env/output.txt rename to acceptance/cmd/api/profile-default-vs-env/output.txt diff --git a/acceptance/cmd/api/default-profile-vs-env/script b/acceptance/cmd/api/profile-default-vs-env/script similarity index 100% rename from acceptance/cmd/api/default-profile-vs-env/script rename to acceptance/cmd/api/profile-default-vs-env/script diff --git a/acceptance/cmd/api/default-profile-vs-env/test.toml b/acceptance/cmd/api/profile-default-vs-env/test.toml similarity index 100% rename from acceptance/cmd/api/default-profile-vs-env/test.toml rename to acceptance/cmd/api/profile-default-vs-env/test.toml diff --git a/acceptance/cmd/api/default-profile/home/.databrickscfg.tmpl b/acceptance/cmd/api/profile-default/home/.databrickscfg.tmpl similarity index 100% rename from acceptance/cmd/api/default-profile/home/.databrickscfg.tmpl rename to acceptance/cmd/api/profile-default/home/.databrickscfg.tmpl diff --git a/acceptance/cmd/api/workspace-id-flag/out.test.toml b/acceptance/cmd/api/profile-default/out.test.toml similarity index 100% rename from acceptance/cmd/api/workspace-id-flag/out.test.toml rename to acceptance/cmd/api/profile-default/out.test.toml diff --git a/acceptance/cmd/api/default-profile/output.txt b/acceptance/cmd/api/profile-default/output.txt similarity index 100% rename from acceptance/cmd/api/default-profile/output.txt rename to acceptance/cmd/api/profile-default/output.txt diff --git a/acceptance/cmd/api/default-profile/script b/acceptance/cmd/api/profile-default/script similarity index 100% rename from acceptance/cmd/api/default-profile/script rename to acceptance/cmd/api/profile-default/script diff --git a/acceptance/cmd/api/default-profile/test.toml b/acceptance/cmd/api/profile-default/test.toml similarity index 100% rename from acceptance/cmd/api/default-profile/test.toml rename to acceptance/cmd/api/profile-default/test.toml diff --git a/acceptance/cmd/api/request-handling/output.txt b/acceptance/cmd/api/request-handling/output.txt deleted file mode 100644 index 467db6038ec..00000000000 --- a/acceptance/cmd/api/request-handling/output.txt +++ /dev/null @@ -1,30 +0,0 @@ - -=== Accept: application/json is sent (the raw response target must not drop it) - -OK: Accept header present - -=== A literal 'null' --json sends no request body (not the bytes "null") - ->>> print_requests.py //test/req --del-field headers -{ - "method": "POST", - "path": "/api/2.0/test/req" -} - -=== Query parameters in the path and a --json body are both sent - ->>> print_requests.py //test/req --del-field headers -{ - "method": "POST", - "path": "/api/2.0/test/req", - "q": { - "foo": "bar", - "x": "1" - }, - "body": { - "hello": "world" - } -} - -=== Malformed --json is rejected client-side with a positioned error -Error: error decoding JSON at (inline):1:8: invalid character ',' looking for beginning of value diff --git a/acceptance/cmd/api/request-handling/script b/acceptance/cmd/api/request-handling/script deleted file mode 100644 index f9efdb0396c..00000000000 --- a/acceptance/cmd/api/request-handling/script +++ /dev/null @@ -1,17 +0,0 @@ -# Behaviours of how `databricks api` builds the outgoing request. - -title "Accept: application/json is sent (the raw response target must not drop it)" -MSYS_NO_PATHCONV=1 $CLI api post /api/2.0/test/req --json '{"a": 1}' > /dev/null -print_requests.py //test/req | contains.py '"Accept"' '"application/json"' > /dev/null -printf '\n%s\n' "OK: Accept header present" - -title "A literal 'null' --json sends no request body (not the bytes \"null\")" -MSYS_NO_PATHCONV=1 $CLI api post /api/2.0/test/req --json 'null' > /dev/null -trace print_requests.py //test/req --del-field headers - -title "Query parameters in the path and a --json body are both sent" -MSYS_NO_PATHCONV=1 $CLI api post "/api/2.0/test/req?foo=bar&x=1" --json '{"hello": "world"}' > /dev/null -trace print_requests.py //test/req --del-field headers - -title "Malformed --json is rejected client-side with a positioned error" -MSYS_NO_PATHCONV=1 musterr $CLI api post /api/2.0/test/req --json '{"a": 1,}' diff --git a/acceptance/cmd/api/response-handling/output.txt b/acceptance/cmd/api/response-handling/output.txt deleted file mode 100644 index 11719fed44b..00000000000 --- a/acceptance/cmd/api/response-handling/output.txt +++ /dev/null @@ -1,20 +0,0 @@ - -=== Empty response body renders null - ->>> [CLI] api get /api/2.0/test/empty -null - -=== A trailing newline in the body does not add a blank line - ->>> [CLI] api get /api/2.0/test/trailing -{ - "ok": true -} - -=== An HTML response surfaces the SDK's actionable error - -OK: HTML detected - -=== A malformed JSON response surfaces an unmarshal error - -OK: unmarshal error reported diff --git a/acceptance/cmd/api/response-handling/test.toml b/acceptance/cmd/api/response-handling/test.toml deleted file mode 100644 index 8689303a8a7..00000000000 --- a/acceptance/cmd/api/response-handling/test.toml +++ /dev/null @@ -1,18 +0,0 @@ -# Fixtures for the response-rendering edge cases. The HTML and malformed bodies -# must surface the SDK's errors (the *json.RawMessage target keeps that -# handling); the trailing newline must not produce a blank line. -[[Server]] -Pattern = "GET /api/2.0/test/empty" -Response.Body = '' - -[[Server]] -Pattern = "GET /api/2.0/test/trailing" -Response.Body = "{\"ok\": true}\n" - -[[Server]] -Pattern = "GET /api/2.0/test/html" -Response.Body = '