MCPcopy Index your code
hub / github.com/google/go-github / testJSONBody

Function testJSONBody

github/github_test.go:223–239  ·  view source on GitHub ↗
(t *testing.T, r *http.Request, want T)

Source from the content-addressed store, hash-verified

221}
222
223func testJSONBody[T any](t *testing.T, r *http.Request, want T) {
224 t.Helper()
225 b, err := io.ReadAll(r.Body)
226 if err != nil {
227 t.Errorf("Error reading request body: %v", err)
228 }
229
230 var got T
231
232 if err := json.Unmarshal(b, &got); err != nil {
233 t.Errorf("Error unmarshaling request body JSON: %v", err)
234 }
235
236 if diff := cmp.Diff(want, got); diff != "" {
237 t.Errorf("request JSON body mismatch (-want +got):\n%v", diff)
238 }
239}
240
241// testJSONMarshal tests both JSON marshaling and unmarshaling of a value by comparing
242// the marshaled output with the expected JSON string.

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…