MCPcopy Create free account
hub / github.com/google/go-github / testJSONUnmarshalOnly

Function testJSONUnmarshalOnly

github/github_test.go:295–306  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

293// In most cases, use testJSONMarshal instead.
294// Only use this function in rare cases where you need to test unmarshaling behavior in isolation.
295func 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.

Callers 1

testJSONMarshalFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…