approvals / go-approval-tests

Apache License 2.0
90 stars 22 forks source link

VerifyJSONBytes requires `map[string]interface{}` #39

Open newhook opened 2 years ago

newhook commented 2 years ago

Why does this require the object demarshal to a map[string]interface{}? The bytes could equally well contain any valid json (arrays, strings, and so on).

    t.Helper()
    var obj map[string]interface{}
    err := json.Unmarshal(bs, &obj)
    if err != nil {
        message := fmt.Sprintf("error while parsing JSON\nerror:\n  %s\nJSON:\n  %s\n", err, string(bs))
        Verify(t, strings.NewReader(message), alwaysOption(opts).WithExtension(".json"))
    } else {
        VerifyJSONStruct(t, obj, opts...)
    }
}