Open bardzusny opened 2 years ago
A proof-of-concept PR implementing https://github.com/approvals/go-approval-tests/issues/38 .
Ignore the implementation details for now, focus on the public API.
If it looks right then we can work on it! (I'll also happily rebase commits to fit the preferred notation.)
Adds basic support for scrubbing values by passed JSONPath. To be used with approvals.VerifyJsonStruct(...) and approvals.VerifyJSONBytes(...).
approvals.VerifyJsonStruct(...)
approvals.VerifyJSONBytes(...)
Usage examples:
opts := approvals.Options().WithJSONPathScrubber("id", "<scrubbed_id>") jb := []byte(`{ "id": 1 }`) approvals.VerifyJSONBytes(t, jb, opts)
Also works for scrubbing properties in lists of objects:
opts := approvals.Options().WithJSONPathScrubber("items[*].id", "<scrubbed_id>") jb := []byte(`{ "items": [{ "id": 1 }, { "id": 2 }] }`) approvals.VerifyJSONBytes(t, jb, opts)
What happens during scrubbing:
What's nice: it works and should be good great for most common usage:
The things left to iterate on (in this PR or later):
simplejson
A proof-of-concept PR implementing https://github.com/approvals/go-approval-tests/issues/38 .
Ignore the implementation details for now, focus on the public API.
If it looks right then we can work on it! (I'll also happily rebase commits to fit the preferred notation.)
Description
Adds basic support for scrubbing values by passed JSONPath. To be used with
approvals.VerifyJsonStruct(...)
andapprovals.VerifyJSONBytes(...)
.Usage examples:
Also works for scrubbing properties in lists of objects:
The solution
What happens during scrubbing:
What's nice: it works and should be good great for most common usage:
The things left to iterate on (in this PR or later):
simplejson
dependency.