Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verifyOptions.WithCustomScrubber: ability to pass a custom scrubber func #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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)
}

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.

1 participant