Closed fabstu closed 3 years ago
Can you help me to understand how you would write your test with a regular Go test (or unit test generally)?
It seems like you're producing a non-deterministic string/[]byte output, and cannot compare that with anything in a stable way - so it's hard to imagine what the desired behavior here is exactly
The template contains a %s
. I read my current want-template from disk, run fmt.Sprintf(wantTemplate
with the value for this run and then do the comparison based on the sprintf-output.
Thinking about this, autogold is supposed to automatically generate the want, but my sprintf relies on my placing the %s
manually. This manual step seems incompatible with Autogold. I think I will replace the pre-known value in got with a placeholder, so autogold only sees the placeholder and does not have to be modified.
Good idea! 👍
A step where autogold calls a foreign method to modify got before storing it as want in -update
seems possible, but that makes autogold way more complicated than it has to be. I can simply modify got before it reaches that point.
I have want-data for which part of got is dynamic.
My example is this. This is the want-data:
I read this data, do
want := fmt.Sprintf(wantRaw, path)
and then compare withassert.Equal
:I can't see how to do this with
autogold.Equal
at the moment. Any ideas? I guess generics would be an easy solution but that's still a long time out. :-)