Skip to content

Conversation

@bardzusny
Copy link

A proof-of-concept PR implementing ability to pass a custom scrubbing function.

It received the verified string and a replacer, returns a scrubbed verified string.

Seems like a legit shortcut to make scrubbing API much more flexible. Got this idea when working on #42 .

I'd appreciate a check on the public API more than anything, and if the idea seems valid overall. Then we can work out the details (+ things like the preferred commit notation/format).

Description

Usage examples:

// replaces "Hello" with the replacer string:
func scrubFunc(s, replacer string) string {
	return regexp.MustCompile("Hello").ReplaceAllString(s, replacer)
}

func TestVerifyJSONBytesWithCustomScrubber(t *testing.T) {
	opts := approvals.Options().WithCustomScrubber(scrubFunc, "Hi")

	jb := []byte("{ \"Greeting\": \"Hello\" }")
	approvals.VerifyJSONBytes(t, jb, opts)
}

@aleclerc-cio
Copy link
Contributor

You can now do this using scrubbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants