franiglesias / golden

Golang Library for snapshot testing
MIT License
3 stars 2 forks source link

Managing no deterministic output #5

Closed franiglesias closed 9 months ago

franiglesias commented 9 months ago

Manage not deterministic data using scrubbers.

Scrubbers can work using regexp to locate specific info and replace with a static representation. It could be something like "removed for testing", or maybe a valid example of data, but I thing it should be marked some way. This can be a problem if we want to use the snapshot as an example.

We should be able to pass any number of scrubbers.

We should be able to ask for predefined scrubbers, because there are lots of common cases.

The place for scrubbing should be the Normalizer.

franiglesias commented 9 months ago

After reading this, I think I could go this way for current test options

https://approvaltestscpp.readthedocs.io/en/latest/generated_docs/explanations/WhyWeAreConvertingToOptions.html

And this

https://approvaltestscpp.readthedocs.io/en/latest/generated_docs/explanations/WhyWeAreConvertingToOptions.html

So, api could be something like:

golden.Verify(t, subject, Options().UseScrubber(NewDateScrubber()))

Options() should be able to handle all options that apply to a specific test.

Options().UseScrubber()
Options().UseSnapshot()
Options().InFolder()
Options().WithExt()
Options().UseReporter()

Internally, Options should resolve to a complete set of options. Something like this constructor that should create a new Options merging the data received with a new options object

testOptions := CloneOptions(receivedOptions)
franiglesias commented 9 months ago

We are going with the functional Options pattern. For Scrubeers we could have an Option function able to pass a list of Scrubbers to use

franiglesias commented 9 months ago

Also, we should differentiate scrubbers from filters. For example, filters could clean subject Itrim... etc)