-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
! F added Noop and MultiScrubber, refactored scrubbers
- Loading branch information
1 parent
9caa58a
commit 6b76b38
Showing
2 changed files
with
54 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package approvals | ||
|
||
import "regexp" | ||
|
||
type scrubber func(s string) string | ||
|
||
// Deprecated: WithRegexScrubber allows you to 'scrub' dynamic data such as timestamps within your test input | ||
// and replace it with a static placeholder | ||
func (v verifyOptions) WithRegexScrubber(regex *regexp.Regexp, replacer string) verifyOptions { | ||
return v.AddScrubber(func(s string) string { | ||
return regex.ReplaceAllString(s, replacer) | ||
}) | ||
} | ||
|
||
// CreateRegexScrubber allows you to create a scrubber that uses a regular expression to scrub data | ||
func CreateRegexScrubber(regex *regexp.Regexp, replacer string) scrubber { | ||
return func(s string) string { | ||
return regex.ReplaceAllString(s, replacer) | ||
} | ||
} | ||
|
||
// NoopScrubber is a scrubber that does nothing | ||
func NoopScrubber(s string) string { | ||
return s | ||
} | ||
|
||
// CreateMultiScrubber allows you to chain multiple scrubbers together | ||
func CreateMultiScrubber(scrubbers ...scrubber) scrubber { | ||
return func(s string) string { | ||
for _, scrubber := range scrubbers { | ||
s = scrubber(s) | ||
} | ||
return s | ||
} | ||
} |