jdockerty / jsonnet-playground

Playground for Jsonnet, inspired by Go/Rust projects of similar names.
https://jsonnet.jdocklabs.co.uk
MIT License
2 stars 0 forks source link

Update table tests to use an `expected` field #25

Closed jdockerty closed 6 months ago

jdockerty commented 6 months ago

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
    }{...}

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