(t *testing.T, url, bearer string, body any)
| 76 | } |
| 77 | |
| 78 | func postJSON(t *testing.T, url, bearer string, body any) (int, map[string]any) { |
| 79 | t.Helper() |
| 80 | b, _ := json.Marshal(body) |
| 81 | req, _ := http.NewRequest("POST", url, bytes.NewReader(b)) |
| 82 | req.Header.Set("Content-Type", "application/json") |
| 83 | if bearer != "" { |
| 84 | req.Header.Set("Authorization", "Bearer "+bearer) |
| 85 | } |
| 86 | resp, err := http.DefaultClient.Do(req) |
| 87 | if err != nil { |
| 88 | t.Fatal(err) |
| 89 | } |
| 90 | defer resp.Body.Close() |
| 91 | var out map[string]any |
| 92 | _ = json.NewDecoder(resp.Body).Decode(&out) |
| 93 | return resp.StatusCode, out |
| 94 | } |
| 95 | |
| 96 | func errCode(body map[string]any) string { |
| 97 | if e, ok := body["error"].(map[string]any); ok { |
no test coverage detected