testJSONUnmarshalOnly tests JSON unmarshaling by parsing the JSON string and comparing the result with the expected value. In most cases, use testJSONMarshal instead. Only use this function in rare cases where you need to test unmarshaling behavior in isolation.
(t *testing.T, want T, v string, opts ...cmp.Option)
| 293 | // In most cases, use testJSONMarshal instead. |
| 294 | // Only use this function in rare cases where you need to test unmarshaling behavior in isolation. |
| 295 | func testJSONUnmarshalOnly[T any](t *testing.T, want T, v string, opts ...cmp.Option) { |
| 296 | t.Helper() |
| 297 | |
| 298 | var got T |
| 299 | if err := json.Unmarshal([]byte(v), &got); err != nil { |
| 300 | t.Fatalf("Unable to unmarshal JSON %v: %v", v, err) |
| 301 | } |
| 302 | |
| 303 | if diff := cmp.Diff(want, got, opts...); diff != "" { |
| 304 | t.Errorf("json.Unmarshal returned:\n%#v\nwant:\n%#v\ndiff:\n%v", got, want, diff) |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | // cmpJSONRawMessageComparator returns an option for use in testJSONUnmarshalData that compares |
| 309 | // json.RawMessage values by their semantic JSON content rather than byte-for-byte equality. |
no outgoing calls
no test coverage detected
searching dependent graphs…