(t *testing.T, r *http.Request, want T)
| 221 | } |
| 222 | |
| 223 | func 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. |
no outgoing calls
no test coverage detected
searching dependent graphs…