(t *testing.T, client *http.Client, method string, requestURL string, token string, payload interface{}, want int)
| 367 | } |
| 368 | |
| 369 | func accessGroupsE2ERequestJSON(t *testing.T, client *http.Client, method string, requestURL string, token string, payload interface{}, want int) interface{} { |
| 370 | t.Helper() |
| 371 | |
| 372 | var body io.Reader |
| 373 | if payload != nil { |
| 374 | payloadBytes, err := json.Marshal(payload) |
| 375 | if err != nil { |
| 376 | t.Fatalf("marshal payload: %v", err) |
| 377 | } |
| 378 | body = bytes.NewReader(payloadBytes) |
| 379 | } |
| 380 | req, err := http.NewRequest(method, requestURL, body) |
| 381 | if err != nil { |
| 382 | t.Fatalf("create request: %v", err) |
| 383 | } |
| 384 | if payload != nil { |
| 385 | if strings.Contains(requestURL, "/api/") { |
| 386 | req.Header.Set("Content-Type", "application/vnd.api+json") |
| 387 | } else { |
| 388 | req.Header.Set("Content-Type", "application/json") |
| 389 | } |
| 390 | } |
| 391 | if token != "" { |
| 392 | req.Header.Set("Authorization", "Bearer "+token) |
| 393 | } |
| 394 | resp, err := client.Do(req) |
| 395 | if err != nil { |
| 396 | t.Fatalf("%s %s failed: %v", method, requestURL, err) |
| 397 | } |
| 398 | defer resp.Body.Close() |
| 399 | responseBody, _ := io.ReadAll(resp.Body) |
| 400 | if resp.StatusCode != want { |
| 401 | t.Fatalf("%s %s returned %d, want %d: %s", method, requestURL, resp.StatusCode, want, string(responseBody)) |
| 402 | } |
| 403 | if len(bytes.TrimSpace(responseBody)) == 0 { |
| 404 | return nil |
| 405 | } |
| 406 | var decoded interface{} |
| 407 | if err := json.Unmarshal(responseBody, &decoded); err != nil { |
| 408 | t.Fatalf("%s %s returned invalid JSON: %v\n%s", method, requestURL, err, string(responseBody)) |
| 409 | } |
| 410 | return decoded |
| 411 | } |
| 412 | |
| 413 | func accessGroupsE2ERecordPayload(entity string, id string, attributes map[string]interface{}) map[string]interface{} { |
| 414 | data := map[string]interface{}{ |
no test coverage detected