Add --diff to compare a response against a JSON baseline#273
Open
jongio wants to merge 1 commit into
Open
Conversation
--diff <file> canonicalizes the JSON response and a saved baseline (sorted keys, normalized whitespace) and prints a unified diff when they differ, exiting non-zero so snapshot checks in CI can catch drift. Object key order no longer produces false diffs, so only real value changes show up. Exit codes follow the existing contract: a clean match exits 0, drift exits 1, and a missing or non-JSON baseline (or a non-JSON response) exits 2. Closes #266 Co-authored-by: Copilot App <[email protected]>
Contributor
|
🚀 Website Preview Your PR preview is ready! 📎 Preview URL: https://jongio.github.io/azd-rest/pr/273/ 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 273 -Version 0.5.0-pr273"Bash (macOS/Linux): curl -fsSL https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/install-pr.sh | bash -s 273 0.5.0-pr273UninstallPowerShell (Windows): iex "& { $(irm https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/uninstall-pr.ps1) } -PrNumber 273"Bash (macOS/Linux): curl -fsSL https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/uninstall-pr.sh | bash -s 273Build 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
--diff <file>flag that compares the JSON response against a saved baseline and prints a unified diff, exiting non-zero when they differ. This turnsazd restinto a snapshot-testing tool for APIs in CI.Both the response and the baseline are canonicalized (parsed as JSON, re-encoded with sorted object keys and normalized whitespace) before comparison, so a change in key order or formatting does not produce a false diff. Only real value changes show up.
Behavior
0.baselinevsresponse, 3 lines of context) to stdout and exits1.2(usage/config), consistent with the existing exit-code contract.--diffis terminal: it replaces the normal body output so the diff is the only thing on stdout, which keeps it easy to capture or pipe.Example
Notes
client.IsJSONfor the response-type guard, matching howservice.goandcolor.goalready gate JSON handling.github.com/pmezard/go-difflibfrom an indirect to a direct dependency (it was already in the module graph via testify). No new third-party code is pulled in.Tests cover key-order insensitivity (top level and nested), drift output, and the three exit-code-2 cases, plus end-to-end match and drift through
Execute.Closes #266