diff --git a/github/gists_test.go b/github/gists_test.go index 170f3393d68..3e6c85ce059 100644 --- a/github/gists_test.go +++ b/github/gists_test.go @@ -6,7 +6,6 @@ package github import ( - "encoding/json" "fmt" "net/http" "testing" @@ -273,13 +272,8 @@ func TestGistsService_Create(t *testing.T) { } mux.HandleFunc("/gists", func(w http.ResponseWriter, r *http.Request) { - var v *Gist - assertNilError(t, json.NewDecoder(r.Body).Decode(&v)) - testMethod(t, r, "POST") - if !cmp.Equal(v, input) { - t.Errorf("Request body = %+v, want %+v", v, input) - } + testJSONBody(t, r, input) fmt.Fprint(w, ` @@ -335,13 +329,8 @@ func TestGistsService_Edit(t *testing.T) { } mux.HandleFunc("/gists/1", func(w http.ResponseWriter, r *http.Request) { - var v *Gist - assertNilError(t, json.NewDecoder(r.Body).Decode(&v)) - testMethod(t, r, "PATCH") - if !cmp.Equal(v, input) { - t.Errorf("Request body = %+v, want %+v", v, input) - } + testJSONBody(t, r, input) fmt.Fprint(w, ` diff --git a/github/git_commits_test.go b/github/git_commits_test.go index 8bbdc8f94a9..949e6fec4a0 100644 --- a/github/git_commits_test.go +++ b/github/git_commits_test.go @@ -6,7 +6,6 @@ package github import ( - "encoding/json" "errors" "fmt" "io" @@ -232,10 +231,9 @@ Commit Message.` Author: &author, Signature: &signature, } - var gotBody *createCommit mux.HandleFunc("/repos/o/r/git/commits", func(w http.ResponseWriter, r *http.Request) { - assertNilError(t, json.NewDecoder(r.Body).Decode(&gotBody)) testMethod(t, r, "POST") + testJSONBody(t, r, wantBody) fmt.Fprintf(w, `{"sha":"%v"}`, sha) }) ctx := t.Context() @@ -243,9 +241,6 @@ Commit Message.` opts := CreateCommitOptions{Signer: mockSigner(t, signature, nil, wantMessage)} commit, _, err := client.Git.CreateCommit(ctx, "o", "r", input, &opts) assertNilError(t, err) - if cmp.Diff(gotBody, wantBody) != "" { - t.Errorf("Request body = %+v, want %+v\n%v", gotBody, wantBody, cmp.Diff(gotBody, wantBody)) - } if cmp.Diff(commit, wantCommit) != "" { t.Errorf("Git.CreateCommit returned %+v, want %+v\n%v", commit, wantCommit, cmp.Diff(commit, wantCommit)) } diff --git a/github/git_trees_test.go b/github/git_trees_test.go index 87ef67a0761..5c269ef0526 100644 --- a/github/git_trees_test.go +++ b/github/git_trees_test.go @@ -6,9 +6,7 @@ package github import ( - "bytes" "fmt" - "io" "net/http" "testing" @@ -85,17 +83,15 @@ func TestGitService_CreateTree(t *testing.T) { } mux.HandleFunc("/repos/o/r/git/trees", func(w http.ResponseWriter, r *http.Request) { - got, err := io.ReadAll(r.Body) - if err != nil { - t.Fatalf("unable to read body: %v", err) - } - testMethod(t, r, "POST") - - want := []byte(`{"base_tree":"b","tree":[{"sha":"7c258a9869f33c1e1e1f74fbb32f07c86cb5a75b","path":"file.rb","mode":"100644","type":"blob"}]}` + "\n") - if !bytes.Equal(got, want) { - t.Errorf("Git.CreateTree request body: %v, want %v", got, want) - } + testJSONBody(t, r, createTree{BaseTree: "b", Entries: []any{ + map[string]any{ + "path": "file.rb", + "mode": "100644", + "type": "blob", + "sha": "7c258a9869f33c1e1e1f74fbb32f07c86cb5a75b", + }, + }}) fmt.Fprint(w, `{ "sha": "cd8274d15fa3ae2ab983129fb037999f264ba9a7", @@ -163,17 +159,14 @@ func TestGitService_CreateTree_Content(t *testing.T) { } mux.HandleFunc("/repos/o/r/git/trees", func(w http.ResponseWriter, r *http.Request) { - got, err := io.ReadAll(r.Body) - if err != nil { - t.Fatalf("unable to read body: %v", err) - } - testMethod(t, r, "POST") - - want := []byte(`{"base_tree":"b","tree":[{"path":"content.md","mode":"100644","content":"file content"}]}` + "\n") - if !bytes.Equal(got, want) { - t.Errorf("Git.CreateTree request body: %v, want %v", got, want) - } + testJSONBody(t, r, createTree{BaseTree: "b", Entries: []any{ + map[string]any{ + "path": "content.md", + "mode": "100644", + "content": "file content", + }, + }}) fmt.Fprint(w, `{ "sha": "5c6780ad2c68743383b740fd1dab6f6a33202b11", @@ -243,17 +236,14 @@ func TestGitService_CreateTree_Delete(t *testing.T) { } mux.HandleFunc("/repos/o/r/git/trees", func(w http.ResponseWriter, r *http.Request) { - got, err := io.ReadAll(r.Body) - if err != nil { - t.Fatalf("unable to read body: %v", err) - } - testMethod(t, r, "POST") - - want := []byte(`{"base_tree":"b","tree":[{"sha":null,"path":"content.md","mode":"100644"}]}` + "\n") - if !bytes.Equal(got, want) { - t.Errorf("Git.CreateTree request body: %v, want %v", got, want) - } + testJSONBody(t, r, createTree{BaseTree: "b", Entries: []any{ + map[string]any{ + "sha": nil, + "path": "content.md", + "mode": "100644", + }, + }}) fmt.Fprint(w, `{ "sha": "5c6780ad2c68743383b740fd1dab6f6a33202b11", diff --git a/github/orgs_rules_test.go b/github/orgs_rules_test.go index 0038742f0e6..3d583f321f0 100644 --- a/github/orgs_rules_test.go +++ b/github/orgs_rules_test.go @@ -6,7 +6,6 @@ package github import ( - "encoding/json" "fmt" "net/http" "testing" @@ -1592,17 +1591,15 @@ func TestOrganizationsService_UpdateRepositoryRuleset_OmitZero_Nil(t *testing.T) t.Parallel() client, mux, _ := setup(t) + input := RepositoryRuleset{ + Name: "test ruleset", + Enforcement: RulesetEnforcementActive, + BypassActors: nil, + } + mux.HandleFunc("/orgs/o/rulesets/21", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") - - var v map[string]any - if err := json.NewDecoder(r.Body).Decode(&v); err != nil { - t.Errorf("could not decode body: %v", err) - } - - if _, ok := v["bypass_actors"]; ok { - t.Error("Request body contained 'bypass_actors', expected it to be omitted for nil input") - } + testJSONBody(t, r, input) fmt.Fprint(w, `{ "id": 21, @@ -1614,11 +1611,6 @@ func TestOrganizationsService_UpdateRepositoryRuleset_OmitZero_Nil(t *testing.T) }) ctx := t.Context() - input := RepositoryRuleset{ - Name: "test ruleset", - Enforcement: RulesetEnforcementActive, - BypassActors: nil, - } _, _, err := client.Organizations.UpdateRepositoryRuleset(ctx, "o", 21, input) if err != nil { diff --git a/github/orgs_test.go b/github/orgs_test.go index cbcff64b277..2ea5ecf05ef 100644 --- a/github/orgs_test.go +++ b/github/orgs_test.go @@ -6,7 +6,6 @@ package github import ( - "encoding/json" "fmt" "net/http" "testing" @@ -214,14 +213,9 @@ func TestOrganizationsService_Edit(t *testing.T) { input := &Organization{Login: Ptr("l")} mux.HandleFunc("/orgs/o", func(w http.ResponseWriter, r *http.Request) { - var v *Organization - assertNilError(t, json.NewDecoder(r.Body).Decode(&v)) - testHeader(t, r, "Accept", mediaTypeMemberAllowedRepoCreationTypePreview) testMethod(t, r, "PATCH") - if !cmp.Equal(v, input) { - t.Errorf("Request body = %+v, want %+v", v, input) - } + testJSONBody(t, r, input) fmt.Fprint(w, `{"id":1}`) }) diff --git a/github/projects_test.go b/github/projects_test.go index d2b33960dd5..5851230e1b2 100644 --- a/github/projects_test.go +++ b/github/projects_test.go @@ -9,7 +9,6 @@ import ( "context" "encoding/json" "fmt" - "io" "net/http" "testing" ) @@ -598,18 +597,16 @@ func TestProjectsService_AddOrganizationProjectItem(t *testing.T) { t.Parallel() client, mux, _ := setup(t) + input := &AddProjectItemOptions{Type: Ptr(ProjectV2ItemContentType("Issue")), ID: Ptr(int64(99))} + mux.HandleFunc("/orgs/o/projectsV2/1/items", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") - b, _ := io.ReadAll(r.Body) - body := string(b) - if body != `{"type":"Issue","id":99}`+"\n" { // encoder adds newline - t.Fatalf("unexpected body: %s", body) - } + testJSONBody(t, r, input) fmt.Fprint(w, `{"id":99,"node_id":"PVTI_new"}`) }) ctx := t.Context() - item, _, err := client.Projects.AddOrganizationProjectItem(ctx, "o", 1, &AddProjectItemOptions{Type: Ptr(ProjectV2ItemContentType("Issue")), ID: Ptr(int64(99))}) + item, _, err := client.Projects.AddOrganizationProjectItem(ctx, "o", 1, input) if err != nil { t.Fatalf("Projects.AddOrganizationProjectItem returned error: %v", err) } @@ -718,18 +715,14 @@ func TestProjectsService_GetOrganizationProjectItem_WithFieldsOption(t *testing. func TestProjectsService_UpdateOrganizationProjectItem(t *testing.T) { t.Parallel() client, mux, _ := setup(t) + input := &UpdateProjectItemOptions{Archived: Ptr(true)} mux.HandleFunc("/orgs/o/projectsV2/1/items/17", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") - b, _ := io.ReadAll(r.Body) - body := string(b) - if body != `{"archived":true}`+"\n" { - t.Fatalf("unexpected body: %s", body) - } + testJSONBody(t, r, input) fmt.Fprint(w, `{"id":17}`) }) - archived := true ctx := t.Context() - item, _, err := client.Projects.UpdateOrganizationProjectItem(ctx, "o", 1, 17, &UpdateProjectItemOptions{Archived: &archived}) + item, _, err := client.Projects.UpdateOrganizationProjectItem(ctx, "o", 1, 17, input) if err != nil { t.Fatalf("UpdateOrganizationProjectItem error: %v", err) } @@ -741,15 +734,16 @@ func TestProjectsService_UpdateOrganizationProjectItem(t *testing.T) { func TestProjectsService_UpdateOrganizationProjectItem_error(t *testing.T) { t.Parallel() client, mux, _ := setup(t) + input := &UpdateProjectItemOptions{Archived: Ptr(true)} mux.HandleFunc("/orgs/o/projectsV2/1/items/17", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") + testJSONBody(t, r, input) fmt.Fprint(w, `{"id":17}`) }) - archived := true ctx := t.Context() const methodName = "UpdateProjectItemForOrg" testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Projects.UpdateOrganizationProjectItem(ctx, "o", 1, 17, &UpdateProjectItemOptions{Archived: &archived}) + got, resp, err := client.Projects.UpdateOrganizationProjectItem(ctx, "o", 1, 17, input) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } @@ -760,26 +754,20 @@ func TestProjectsService_UpdateOrganizationProjectItem_error(t *testing.T) { func TestProjectsService_UpdateOrganizationProjectItem_WithFieldUpdates(t *testing.T) { t.Parallel() client, mux, _ := setup(t) + input := &UpdateProjectItemOptions{ + Fields: []*UpdateProjectV2Field{ + {ID: 123, Value: "Updated text value"}, + {ID: 456, Value: "Done"}, + }, + } mux.HandleFunc("/orgs/o/projectsV2/1/items/17", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") - b, _ := io.ReadAll(r.Body) - body := string(b) - // Verify the field updates are properly formatted in the request body - expectedBody := `{"fields":[{"id":123,"value":"Updated text value"},{"id":456,"value":"Done"}]}` - if body != expectedBody+"\n" { - t.Fatalf("unexpected body: %s, expected: %s", body, expectedBody) - } + testJSONBody(t, r, input) fmt.Fprint(w, `{"id":17,"node_id":"PVTI_node_updated"}`) }) ctx := t.Context() - opts := &UpdateProjectItemOptions{ - Fields: []*UpdateProjectV2Field{ - {ID: 123, Value: "Updated text value"}, - {ID: 456, Value: "Done"}, - }, - } - item, _, err := client.Projects.UpdateOrganizationProjectItem(ctx, "o", 1, 17, opts) + item, _, err := client.Projects.UpdateOrganizationProjectItem(ctx, "o", 1, 17, input) if err != nil { t.Fatalf("UpdateOrganizationProjectItem error: %v", err) } @@ -789,11 +777,11 @@ func TestProjectsService_UpdateOrganizationProjectItem_WithFieldUpdates(t *testi const methodName = "UpdateOrganizationProjectItemWithFields" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Projects.UpdateOrganizationProjectItem(ctx, "\n", 1, 17, opts) + _, _, err = client.Projects.UpdateOrganizationProjectItem(ctx, "\n", 1, 17, input) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Projects.UpdateOrganizationProjectItem(ctx, "o", 1, 17, opts) + got, resp, err := client.Projects.UpdateOrganizationProjectItem(ctx, "o", 1, 17, input) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } @@ -871,17 +859,14 @@ func TestProjectsService_ListUserProjectItems_error(t *testing.T) { func TestProjectsService_AddUserProjectItem(t *testing.T) { t.Parallel() client, mux, _ := setup(t) + input := &AddProjectItemOptions{Type: Ptr(ProjectV2ItemContentType("PullRequest")), ID: Ptr(int64(123))} mux.HandleFunc("/users/u/projectsV2/2/items", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") - b, _ := io.ReadAll(r.Body) - body := string(b) - if body != `{"type":"PullRequest","id":123}`+"\n" { - t.Fatalf("unexpected body: %s", body) - } + testJSONBody(t, r, input) fmt.Fprint(w, `{"id":123,"node_id":"PVTI_new_user"}`) }) ctx := t.Context() - item, _, err := client.Projects.AddUserProjectItem(ctx, "u", 2, &AddProjectItemOptions{Type: Ptr(ProjectV2ItemContentType("PullRequest")), ID: Ptr(int64(123))}) + item, _, err := client.Projects.AddUserProjectItem(ctx, "u", 2, input) if err != nil { t.Fatalf("AddUserProjectItem error: %v", err) } @@ -989,18 +974,14 @@ func TestProjectsService_GetUserProjectItem_WithFieldsOption(t *testing.T) { func TestProjectsService_UpdateUserProjectItem(t *testing.T) { t.Parallel() client, mux, _ := setup(t) + input := &UpdateProjectItemOptions{Archived: Ptr(false)} mux.HandleFunc("/users/u/projectsV2/2/items/55", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") - b, _ := io.ReadAll(r.Body) - body := string(b) - if body != `{"archived":false}`+"\n" { - t.Fatalf("unexpected body: %s", body) - } + testJSONBody(t, r, input) fmt.Fprint(w, `{"id":55}`) }) - archived := false ctx := t.Context() - item, _, err := client.Projects.UpdateUserProjectItem(ctx, "u", 2, 55, &UpdateProjectItemOptions{Archived: &archived}) + item, _, err := client.Projects.UpdateUserProjectItem(ctx, "u", 2, 55, input) if err != nil { t.Fatalf("UpdateUserProjectItem error: %v", err) } @@ -1031,25 +1012,19 @@ func TestProjectsService_UpdateUserProjectItem_error(t *testing.T) { func TestProjectsService_UpdateUserProjectItem_WithFieldUpdates(t *testing.T) { t.Parallel() client, mux, _ := setup(t) + opts := &UpdateProjectItemOptions{ + Fields: []*UpdateProjectV2Field{ + {ID: 100, Value: "In Progress"}, + {ID: 200, Value: float64(5)}, // number field + }, + } mux.HandleFunc("/users/u/projectsV2/2/items/55", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") - b, _ := io.ReadAll(r.Body) - body := string(b) - // Verify the field updates are properly formatted in the request body - expectedBody := `{"fields":[{"id":100,"value":"In Progress"},{"id":200,"value":5}]}` - if body != expectedBody+"\n" { - t.Fatalf("unexpected body: %s, expected: %s", body, expectedBody) - } + testJSONBody(t, r, opts) fmt.Fprint(w, `{"id":55,"node_id":"PVTI_user_updated"}`) }) ctx := t.Context() - opts := &UpdateProjectItemOptions{ - Fields: []*UpdateProjectV2Field{ - {ID: 100, Value: "In Progress"}, - {ID: 200, Value: 5}, // number field - }, - } item, _, err := client.Projects.UpdateUserProjectItem(ctx, "u", 2, 55, opts) if err != nil { t.Fatalf("UpdateUserProjectItem error: %v", err) diff --git a/github/pulls_test.go b/github/pulls_test.go index 25ec9325640..19877b1ae46 100644 --- a/github/pulls_test.go +++ b/github/pulls_test.go @@ -6,7 +6,6 @@ package github import ( - "encoding/json" "fmt" "io" "net/http" @@ -359,13 +358,8 @@ func TestPullRequestsService_Create(t *testing.T) { input := &NewPullRequest{Title: Ptr("t")} mux.HandleFunc("/repos/o/r/pulls", func(w http.ResponseWriter, r *http.Request) { - var v *NewPullRequest - assertNilError(t, json.NewDecoder(r.Body).Decode(&v)) - testMethod(t, r, "POST") - if !cmp.Equal(v, input) { - t.Errorf("Request body = %+v, want %+v", v, input) - } + testJSONBody(t, r, input) fmt.Fprint(w, `{"number":1}`) }) diff --git a/github/repos_comments_test.go b/github/repos_comments_test.go index e0bb94a32ea..7cebb99dad9 100644 --- a/github/repos_comments_test.go +++ b/github/repos_comments_test.go @@ -6,7 +6,6 @@ package github import ( - "encoding/json" "fmt" "net/http" "testing" @@ -207,13 +206,8 @@ func TestRepositoriesService_UpdateComment(t *testing.T) { input := &RepositoryComment{Body: Ptr("b")} mux.HandleFunc("/repos/o/r/comments/1", func(w http.ResponseWriter, r *http.Request) { - var v *RepositoryComment - assertNilError(t, json.NewDecoder(r.Body).Decode(&v)) - testMethod(t, r, "PATCH") - if !cmp.Equal(v, input) { - t.Errorf("Request body = %+v, want %+v", v, input) - } + testJSONBody(t, r, input) fmt.Fprint(w, `{"id":1}`) }) diff --git a/github/repos_pages_test.go b/github/repos_pages_test.go index 10c67a920a8..227cbcb688b 100644 --- a/github/repos_pages_test.go +++ b/github/repos_pages_test.go @@ -6,9 +6,7 @@ package github import ( - "bytes" "fmt" - "io" "net/http" "testing" @@ -217,16 +215,8 @@ func TestRepositoriesService_UpdatePages_NullCNAME(t *testing.T) { } mux.HandleFunc("/repos/o/r/pages", func(w http.ResponseWriter, r *http.Request) { - got, err := io.ReadAll(r.Body) - if err != nil { - t.Fatalf("unable to read body: %v", err) - } - - want := []byte(`{"cname":null,"source":{"branch":"gh-pages"}}` + "\n") - if !bytes.Equal(got, want) { - t.Errorf("Request body = %+v, want %+v", got, want) - } - + testMethod(t, r, "PUT") + testJSONBody(t, r, input) fmt.Fprint(w, `{"cname":null,"source":{"branch":"gh-pages"}}`) }) diff --git a/github/repos_rules_test.go b/github/repos_rules_test.go index ff93fbd4887..33df6ab4857 100644 --- a/github/repos_rules_test.go +++ b/github/repos_rules_test.go @@ -6,7 +6,6 @@ package github import ( - "encoding/json" "fmt" "net/http" "testing" @@ -138,17 +137,15 @@ func TestRepositoriesService_UpdateRuleset_OmitZero_Nil(t *testing.T) { t.Parallel() client, mux, _ := setup(t) + input := RepositoryRuleset{ + Name: "ruleset", + Enforcement: RulesetEnforcementActive, + BypassActors: nil, + } + mux.HandleFunc("/repos/o/repo/rulesets/42", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") - - var v map[string]any - if err := json.NewDecoder(r.Body).Decode(&v); err != nil { - t.Errorf("could not decode body: %v", err) - } - - if _, ok := v["bypass_actors"]; ok { - t.Error("Request body contained 'bypass_actors', expected it to be omitted for nil input") - } + testJSONBody(t, r, input) fmt.Fprint(w, `{ "id": 42, @@ -159,11 +156,6 @@ func TestRepositoriesService_UpdateRuleset_OmitZero_Nil(t *testing.T) { }) ctx := t.Context() - input := RepositoryRuleset{ - Name: "ruleset", - Enforcement: RulesetEnforcementActive, - BypassActors: nil, - } _, _, err := client.Repositories.UpdateRuleset(ctx, "o", "repo", 42, input) if err != nil { diff --git a/github/teams_test.go b/github/teams_test.go index e3287bdf50b..dc3493fbd6a 100644 --- a/github/teams_test.go +++ b/github/teams_test.go @@ -6,10 +6,7 @@ package github import ( - "bytes" - "encoding/json" "fmt" - "io" "net/http" "testing" @@ -275,21 +272,10 @@ func TestTeamsService_EditTeamByID_RemoveParent(t *testing.T) { client, mux, _ := setup(t) input := NewTeam{Name: "n", NotificationSetting: Ptr("notifications_enabled"), Privacy: Ptr("closed")} - var body string mux.HandleFunc("/organizations/1/team/1", func(w http.ResponseWriter, r *http.Request) { - buf, err := io.ReadAll(r.Body) - if err != nil { - t.Errorf("Unable to read body: %v", err) - } - body = string(buf) - var v *NewTeam - assertNilError(t, json.NewDecoder(bytes.NewBuffer(buf)).Decode(&v)) - testMethod(t, r, "PATCH") - if !cmp.Equal(v, &input) { - t.Errorf("Request body = %+v, want %+v", v, input) - } + testJSONBody(t, r, input) fmt.Fprint(w, `{"id":1}`) }) @@ -304,10 +290,6 @@ func TestTeamsService_EditTeamByID_RemoveParent(t *testing.T) { if !cmp.Equal(team, want) { t.Errorf("Teams.EditTeamByID returned %+v, want %+v", team, want) } - - if want := `{"name":"n","parent_team_id":null,"notification_setting":"notifications_enabled","privacy":"closed"}` + "\n"; body != want { - t.Errorf("Teams.EditTeamByID body = %+v, want %+v", body, want) - } } func TestTeamsService_EditTeamBySlug(t *testing.T) { @@ -353,21 +335,10 @@ func TestTeamsService_EditTeamBySlug_RemoveParent(t *testing.T) { client, mux, _ := setup(t) input := NewTeam{Name: "n", NotificationSetting: Ptr("notifications_disabled"), Privacy: Ptr("closed")} - var body string mux.HandleFunc("/orgs/o/teams/s", func(w http.ResponseWriter, r *http.Request) { - buf, err := io.ReadAll(r.Body) - if err != nil { - t.Errorf("Unable to read body: %v", err) - } - body = string(buf) - var v *NewTeam - assertNilError(t, json.NewDecoder(bytes.NewBuffer(buf)).Decode(&v)) - testMethod(t, r, "PATCH") - if !cmp.Equal(v, &input) { - t.Errorf("Request body = %+v, want %+v", v, input) - } + testJSONBody(t, r, input) fmt.Fprint(w, `{"id":1}`) }) @@ -375,16 +346,12 @@ func TestTeamsService_EditTeamBySlug_RemoveParent(t *testing.T) { ctx := t.Context() team, _, err := client.Teams.EditTeamBySlug(ctx, "o", "s", input, true) if err != nil { - t.Errorf("Teams.EditTeam returned error: %v", err) + t.Errorf("Teams.EditTeamBySlug returned error: %v", err) } want := &Team{ID: Ptr(int64(1))} if !cmp.Equal(team, want) { - t.Errorf("Teams.EditTeam returned %+v, want %+v", team, want) - } - - if want := `{"name":"n","parent_team_id":null,"notification_setting":"notifications_disabled","privacy":"closed"}` + "\n"; body != want { - t.Errorf("Teams.EditTeam body = %+v, want %+v", body, want) + t.Errorf("Teams.EditTeamBySlug returned %+v, want %+v", team, want) } }