From 20afe17921253dfa23335afb31008683c36916bf Mon Sep 17 00:00:00 2001 From: Stephen Young Date: Wed, 15 Jan 2025 12:58:02 -0500 Subject: [PATCH] - r change options to use a single scrubber instead of a list --- approvals.go | 14 ++++++-------- scrubber.go | 6 ++++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/approvals.go b/approvals.go index ef6d9b5..be71513 100644 --- a/approvals.go +++ b/approvals.go @@ -311,14 +311,14 @@ func Options() verifyOptions { } // WithScrubber allows you to 'scrub' data within your test input and replace it with a static placeholder -func (v verifyOptions) WithScrubbers(scrubbers ...scrubber) verifyOptions { - return NewVerifyOptions(v.fields, "scrubbers", scrubbers) +func (v verifyOptions) WithScrubber(scrub scrubber) verifyOptions { + return NewVerifyOptions(v.fields, "scrubber", scrub) } // AddScrubber allows you to 'scrub' data within your test input and replace it with a static placeholder func (v verifyOptions) AddScrubber(scrubfn scrubber) verifyOptions { - newScrubbers := append(v.getField("scrubbers", []scrubber{}).([]scrubber), scrubfn) - return v.WithScrubbers(newScrubbers...) + scrub := CreateMultiScrubber(v.getField("scrubber", CreateNoopScrubber()).(scrubber), scrubfn) + return v.WithScrubber(scrub) } // WithExtension overrides the default file extension (.txt) for approval files. @@ -335,10 +335,8 @@ func (v verifyOptions) Scrub(reader io.Reader) (io.Reader, error) { return nil, err } - result := string(b) - for _, sb := range v.getField("scrubbers", []scrubber{}).([]scrubber) { - result = sb(result) - } + scrub := v.getField("scrubber", CreateNoopScrubber()).(scrubber) + result := scrub(string(b)) return strings.NewReader(result), nil } diff --git a/scrubber.go b/scrubber.go index 8e0d1eb..dfe60c6 100644 --- a/scrubber.go +++ b/scrubber.go @@ -20,8 +20,10 @@ func CreateRegexScrubber(regex *regexp.Regexp, replacer string) scrubber { } // NoopScrubber is a scrubber that does nothing -func NoopScrubber(s string) string { - return s +func CreateNoopScrubber() scrubber { + return func(s string) string { + return s + } } // CreateMultiScrubber allows you to chain multiple scrubbers together