sebdah / goldie

Golden file testing for Go
MIT License
228 stars 19 forks source link

Update pattern for templated golden files #14

Open gtrevg opened 5 years ago

gtrevg commented 5 years ago

First, thanks for building this package!

I'm trying to leverage the goldie.AssertWithTemplate feature along with the pattern of using the -update flag when the file doesn't exist.

In regards to the template golden file, I would expect the process to be something like:

At that point, everything seems good. Then we

I can imagine that it would be relatively simple to go back and change the one overwritten .Type variable in this case. It is a bit more complex, though, if you had a bunch of variables throughout a large .golden file.

Do you have any thoughts on how to preserve the original template variables while doing an -update? One idea is that on -update, the template code could be smart enough to replace all scalar values in the data passed in with {{ .Dot.Path.To.Key }}. That way, when .Type writes itself out to the golden file, it'll end up writing itself out as {{ .Type }} once again, thus preserving the template variables while updating all the other content of the golden file.

Thanks!