Skip to content

Commit

Permalink
- r change options to use a single scrubber instead of a list
Browse files Browse the repository at this point in the history
  • Loading branch information
hownowstephen committed Jan 15, 2025
1 parent 6b76b38 commit 20afe17
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 6 additions & 8 deletions approvals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions scrubber.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 20afe17

Please sign in to comment.