(t *testing.T)
| 536 | } |
| 537 | |
| 538 | func TestGistsService_Edit(t *testing.T) { |
| 539 | t.Parallel() |
| 540 | client, mux, _ := setup(t) |
| 541 | |
| 542 | input := &Gist{ |
| 543 | Description: Ptr("New description"), |
| 544 | Files: map[GistFilename]GistFile{ |
| 545 | "new.txt": {Content: Ptr("new file content")}, |
| 546 | }, |
| 547 | } |
| 548 | |
| 549 | mux.HandleFunc("/gists/1", func(w http.ResponseWriter, r *http.Request) { |
| 550 | var v *Gist |
| 551 | assertNilError(t, json.NewDecoder(r.Body).Decode(&v)) |
| 552 | |
| 553 | testMethod(t, r, "PATCH") |
| 554 | if !cmp.Equal(v, input) { |
| 555 | t.Errorf("Request body = %+v, want %+v", v, input) |
| 556 | } |
| 557 | |
| 558 | fmt.Fprint(w, |
| 559 | ` |
| 560 | { |
| 561 | "id": "1", |
| 562 | "description": "new description", |
| 563 | "public": false, |
| 564 | "files": { |
| 565 | "test.txt": { |
| 566 | "filename": "test.txt" |
| 567 | }, |
| 568 | "new.txt": { |
| 569 | "filename": "new.txt" |
| 570 | } |
| 571 | } |
| 572 | }`) |
| 573 | }) |
| 574 | |
| 575 | ctx := t.Context() |
| 576 | gist, _, err := client.Gists.Edit(ctx, "1", input) |
| 577 | if err != nil { |
| 578 | t.Errorf("Gists.Edit returned error: %v", err) |
| 579 | } |
| 580 | |
| 581 | want := &Gist{ |
| 582 | ID: Ptr("1"), |
| 583 | Description: Ptr("new description"), |
| 584 | Public: Ptr(false), |
| 585 | Files: map[GistFilename]GistFile{ |
| 586 | "test.txt": {Filename: Ptr("test.txt")}, |
| 587 | "new.txt": {Filename: Ptr("new.txt")}, |
| 588 | }, |
| 589 | } |
| 590 | if !cmp.Equal(gist, want) { |
| 591 | t.Errorf("Gists.Edit returned %+v, want %+v", gist, want) |
| 592 | } |
| 593 | |
| 594 | const methodName = "Edit" |
| 595 | testBadOptions(t, methodName, func() (err error) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…