When I initially wrote these, I started with an expected value and then removed it in favour of simply calling the vm.EvaluateAnonymousSnippet or similar and comparing the output to a clean Jsonnet VM instantiation.
I believe a better way to do this is to compare it to a "known good" JSON file for the output, this reduces the amount of boilerplate too.
This means the table test cases can look like this:
tests := []struct {
name string
input string
expected string // Path to JSON file with output
shouldFail bool
}{...}
When I initially wrote these, I started with an
expected
value and then removed it in favour of simply calling thevm.EvaluateAnonymousSnippet
or similar and comparing the output to a clean Jsonnet VM instantiation.I believe a better way to do this is to compare it to a "known good" JSON file for the output, this reduces the amount of boilerplate too.
This means the table test cases can look like this:
An example of where this was partially done is in the
state
tests, https://github.com/jdockerty/jsonnet-playground/blob/43468877852e17a9ede3a5838a73f204e34bc4cc/internal/server/state/state_test.go#L17-L18