fix: resolve panic on JSON array comparison in body assertions#48
Merged
Conversation
Refactor compare() into compare() + compareValues() to support
[]interface{} (JSON arrays) with strict length matching and indexed
error paths. Also hardens all type assertions with comma-ok pattern
to prevent panics on missing keys or type mismatches.
Closes #36
…overage Compare overlapping elements even when array lengths differ so users see all errors at once. Add tests for primitive arrays and nested arrays. Document precision caveat on int-to-float64 comparison and clarify default case type assumptions.
ARPerry87
approved these changes
Feb 25, 2026
ARPerry87
left a comment
Collaborator
There was a problem hiding this comment.
LGTM but probably should also have Sinan or Zach look it over as well!
Collaborator
Author
|
Tested this branch against the ZTMF project's full E2E suite (73 tests) with real array body assertions that previously panicked on v0.3.1. Test that was panicking: - url: http://localhost:8090/api/v1/cfactssystems
method: GET
headers:
<<: *issoHeaders
expect:
status: 200
body:
json:
data:
- fisma_uuid: "E1D00198-36D4-4EAB-8C00-501E1D000999"
fisma_acronym: "SLD-GEN"Built the branch locally, swapped the binary, ran against an isolated test database — 73/73 passed with 0 failures. No panic, array comparison worked as expected. |
cleong14
approved these changes
Feb 25, 2026
cleong14
left a comment
Collaborator
There was a problem hiding this comment.
LGTM! Logic is sound and confirmed tests are passing.
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.
Summary
compare()intocompare()+compareValues()to handle[]interface{}(JSON arrays) which previously caused a runtime panicbody.json.data[0].name)Closes #36
Test plan
SHOULD PASS with matching JSON arraysSHOULD FAIL with mismatched JSON array elementSHOULD FAIL with JSON array length mismatch