feat: add --expect to assert JMESPath expressions on the response#272
Open
jongio wants to merge 1 commit into
Open
feat: add --expect to assert JMESPath expressions on the response#272jongio wants to merge 1 commit into
jongio wants to merge 1 commit into
Conversation
Add a repeatable --expect flag that evaluates a JMESPath expression against the JSON response and exits non-zero when it does not hold, so a script or CI step can assert on a response without piping --query into test or jq. A bare expression must be truthy under JMESPath rules. The expr=value form requires the result to equal value, comparing scalars by their plain string value so properties.provisioningState=Succeeded and count=3 both work. The split keeps JMESPath comparators (==, !=, <=, >=) intact by only splitting on a standalone =. The response body still prints, then the check runs against the original body so --expect stays independent of --query. An assertion that fails exits 1; a non-JSON response, an empty expression, or an invalid expression exits 2. Closes #269 Co-authored-by: Copilot App <[email protected]>
Contributor
|
🚀 Website Preview Your PR preview is ready! 📎 Preview URL: https://jongio.github.io/azd-rest/pr/272/ This preview will be automatically cleaned up when the PR is closed. |
Contributor
🚀 Test This PRA preview build ( One-Line Install (Recommended)PowerShell (Windows): iex "& { $(irm https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/install-pr.ps1) } -PrNumber 272 -Version 0.5.0-pr272"Bash (macOS/Linux): curl -fsSL https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/install-pr.sh | bash -s 272 0.5.0-pr272UninstallPowerShell (Windows): iex "& { $(irm https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/uninstall-pr.ps1) } -PrNumber 272"Bash (macOS/Linux): curl -fsSL https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/uninstall-pr.sh | bash -s 272Build Info:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a repeatable
--expectflag that evaluates a JMESPath expression against the JSON response and exits non-zero when it does not hold.--expect "<jmespath>"passes when the result is truthy under JMESPath rules (false, null, empty string, empty array, and empty object are falsy; every other value, including any number, is truthy).--expect "<jmespath>=<value>"passes when the result equalsvalue. Scalars compare by their plain string form, soproperties.provisioningState=Succeeded,count=3, andactive=trueall work. A missing field resolves to null, sofield=nullis a valid assertion.--expectseveral times to check more than one thing. The first failing assertion is reported.Why
There is no built-in way to assert something about a response body in a script or CI step. Today you pipe
--queryintotestorjq.--expectfolds that into one call: run the request, print the body, and fail the step when the response is not what you expected.Behavior
--failprints the body before returning its exit code.--expectstays independent of what--querynarrows for display.1; a non-JSON response, an empty expression, or an invalid JMESPath expression exits2.expr=valuesplit only triggers on a standalone=, so JMESPath comparators (==,!=,<=,>=) inside a bare boolean expression are preserved.Example
Tests
--expectworks alongside--query.Docs updated in the README, the reference flag table, and the exit-code table.
Closes #269