Repository: google/go-github
Pull request #1768 (2020-12-26 15:57:08)

Improve repos.go coverage

codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/1768?src=pr&el=h1) Report
> Merging [#1768](https://codecov.io/gh/google/go-github/pull/1768?src=pr&el=desc) (5222e9b) into [master](https://codecov.io/gh/google/go-github/commit/4489191f88a5044c2497dc8e353418e5a54db21a?el=desc) (4489191) will **increase** coverage by `0.15%`.
> The diff coverage is `80.00%`.

[![Impacted file tree graph](https://codecov.io/gh/google/go-github/pull/1768/graphs/tree.svg?width=650&height=150&src=pr&token=EgYjGjZlI0)](https://codecov.io/gh/google/go-github/pull/1768?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1768      +/-   ##
==========================================
+ Coverage   96.94%   97.09%   +0.15%     
==========================================
  Files          98       98              
  Lines        6373     6373              
==========================================
+ Hits         6178     6188      +10     
+ Misses        109      104       -5     
+ Partials       86       81       -5     
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/1768?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [github/github.go](https://codecov.io/gh/google/go-github/pull/1768/diff?src=pr&el=tree#diff-Z2l0aHViL2dpdGh1Yi5nbw==) | `95.31% <0.00%> (ø)` | |
| [github/repos.go](https://codecov.io/gh/google/go-github/pull/1768/diff?src=pr&el=tree#diff-Z2l0aHViL3JlcG9zLmdv) | `98.72% <100.00%> (+2.13%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/go-github/pull/1768?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/google/go-github/pull/1768?src=pr&el=footer). Last update [4489191...5222e9b](https://codecov.io/gh/google/go-github/pull/1768?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/github/github.go b/github/github.go
index 428bc68c..957ac0c7 100644
--- a/github/github.go
+++ b/github/github.go
@@ -909,7 +909,7 @@ func (c *Client) RateLimits(ctx context.Context) (*RateLimits, *Response, error)
 	})
 	resp, err := c.Do(ctx, req, response)
 	if err != nil {
-		return nil, nil, err
+		return nil, resp, err
 	}
 
 	if response.Resources != nil {
diff --git a/github/reactions.go b/github/reactions.go
index 676bf6ac..08387cb5 100644
--- a/github/reactions.go
+++ b/github/reactions.go
@@ -434,7 +434,7 @@ func (s *ReactionsService) ListTeamDiscussionCommentReactions(ctx context.Contex
 	var m []*Reaction
 	resp, err := s.client.Do(ctx, req, &m)
 	if err != nil {
-		return nil, nil, err
+		return nil, resp, err
 	}
 	return m, resp, nil
 }
diff --git a/github/repos.go b/github/repos.go
index 17ffc49c..18510d58 100644
--- a/github/repos.go
+++ b/github/repos.go
@@ -651,7 +651,7 @@ func (s *RepositoriesService) ListContributors(ctx context.Context, owner string
 	var contributor []*Contributor
 	resp, err := s.client.Do(ctx, req, &contributor)
 	if err != nil {
-		return nil, nil, err
+		return nil, resp, err
 	}
 
 	return contributor, resp, nil
@@ -1396,7 +1396,7 @@ func (s *RepositoriesService) ReplaceAppRestrictions(ctx context.Context, owner,
 	var apps []*App
 	resp, err := s.client.Do(ctx, req, &apps)
 	if err != nil {
-		return nil, nil, err
+		return nil, resp, err
 	}
 
 	return apps, resp, nil
@@ -1418,7 +1418,7 @@ func (s *RepositoriesService) AddAppRestrictions(ctx context.Context, owner, rep
 	var apps []*App
 	resp, err := s.client.Do(ctx, req, &apps)
 	if err != nil {
-		return nil, nil, err
+		return nil, resp, err
 	}
 
 	return apps, resp, nil
@@ -1440,7 +1440,7 @@ func (s *RepositoriesService) RemoveAppRestrictions(ctx context.Context, owner,
 	var apps []*App
 	resp, err := s.client.Do(ctx, req, &apps)
 	if err != nil {
-		return nil, nil, err
+		return nil, resp, err
 	}
 
 	return apps, resp, nil


Test patch:
diff --git a/github/github_test.go b/github/github_test.go
index a2c7bda3..e95c2d00 100644
--- a/github/github_test.go
+++ b/github/github_test.go
@@ -1296,6 +1296,19 @@ func TestRateLimits(t *testing.T) {
 	}
 }
 
+func TestRateLimits_coverage(t *testing.T) {
+	client, _, _, teardown := setup()
+	defer teardown()
+
+	ctx := context.Background()
+
+	const methodName = "RateLimits"
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		_, resp, err := client.RateLimits(ctx)
+		return resp, err
+	})
+}
+
 func TestSetCredentialsAsHeaders(t *testing.T) {
 	req := new(http.Request)
 	id, secret := "id", "secret"
diff --git a/github/orgs_members_test.go b/github/orgs_members_test.go
index be010896..ec41b3d7 100644
--- a/github/orgs_members_test.go
+++ b/github/orgs_members_test.go
@@ -292,6 +292,56 @@ func TestOrganizationsService_RemoveMember_invalidOrg(t *testing.T) {
 	testURLParseError(t, err)
 }
 
+func TestOrganizationsService_PublicizeMembership(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/orgs/o/public_members/u", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "PUT")
+	})
+
+	ctx := context.Background()
+	_, err := client.Organizations.PublicizeMembership(ctx, "o", "u")
+	if err != nil {
+		t.Errorf("Organizations.PublicizeMembership returned error: %v", err)
+	}
+
+	const methodName = "PublicizeMembership"
+	testBadOptions(t, methodName, func() (err error) {
+		_, err = client.Organizations.PublicizeMembership(ctx, "\n", "\n")
+		return err
+	})
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		return client.Organizations.PublicizeMembership(ctx, "o", "u")
+	})
+}
+
+func TestOrganizationsService_ConcealMembership(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/orgs/o/public_members/u", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "DELETE")
+	})
+
+	ctx := context.Background()
+	_, err := client.Organizations.ConcealMembership(ctx, "o", "u")
+	if err != nil {
+		t.Errorf("Organizations.ConcealMembership returned error: %v", err)
+	}
+
+	const methodName = "ConcealMembership"
+	testBadOptions(t, methodName, func() (err error) {
+		_, err = client.Organizations.ConcealMembership(ctx, "\n", "\n")
+		return err
+	})
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		return client.Organizations.ConcealMembership(ctx, "o", "u")
+	})
+}
+
 func TestOrganizationsService_ListOrgMemberships(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()
diff --git a/github/pulls_reviews_test.go b/github/pulls_reviews_test.go
index b34168bf..65f84a95 100644
--- a/github/pulls_reviews_test.go
+++ b/github/pulls_reviews_test.go
@@ -322,6 +322,10 @@ func TestPullRequestReviewRequest_isComfortFadePreview(t *testing.T) {
 		name:     "empty review",
 		review:   &PullRequestReviewRequest{},
 		wantBool: false,
+	}, {
+		name:     "nil comment",
+		review:   &PullRequestReviewRequest{Comments: []*DraftReviewComment{nil}},
+		wantBool: false,
 	}, {
 		name: "old-style review",
 		review: &PullRequestReviewRequest{
@@ -487,6 +491,82 @@ func TestPullRequestsService_CreateReview_invalidOwner(t *testing.T) {
 	testURLParseError(t, err)
 }
 
+func TestPullRequestsService_CreateReview_badReview(t *testing.T) {
+	client, _, _, teardown := setup()
+	defer teardown()
+
+	ctx := context.Background()
+
+	path := "path/to/file.go"
+	body := "this is a comment body"
+	right := "RIGHT"
+	pos1 := 1
+	line1 := 11
+	badReview := &PullRequestReviewRequest{
+		Comments: []*DraftReviewComment{{
+			Path: &path,
+			Body: &body,
+			Side: &right,
+			Line: &line1,
+		}, {
+			Path:     &path,
+			Body:     &body,
+			Position: &pos1,
+		}}}
+
+	_, _, err := client.PullRequests.CreateReview(ctx, "o", "r", 1, badReview)
+	if err == nil {
+		t.Errorf("CreateReview badReview err = nil, want err")
+	}
+}
+
+func TestPullRequestsService_CreateReview_addHeader(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	path := "path/to/file.go"
+	body := "this is a comment body"
+	left, right := "LEFT", "RIGHT"
+	line1, line2, line3 := 11, 22, 33
+	input := &PullRequestReviewRequest{
+		Comments: []*DraftReviewComment{{
+			Path: &path,
+			Body: &body,
+			Side: &right,
+			Line: &line1,
+		}, {
+			Path: &path,
+			Body: &body,
+			Side: &left,
+			Line: &line2,
+		}, {
+			Path: &path,
+			Body: &body,
+			Side: &right,
+			Line: &line3,
+		}},
+	}
+
+	mux.HandleFunc("/repos/o/r/pulls/1/reviews", func(w http.ResponseWriter, r *http.Request) {
+		v := new(PullRequestReviewRequest)
+		json.NewDecoder(r.Body).Decode(v)
+
+		testMethod(t, r, "POST")
+		if !reflect.DeepEqual(v, input) {
+			t.Errorf("Request body = %+v, want %+v", v, input)
+		}
+
+		fmt.Fprint(w, `{"id":1}`)
+	})
+
+	ctx := context.Background()
+
+	_, _, err := client.PullRequests.CreateReview(ctx, "o", "r", 1, input)
+	if err != nil {
+		t.Errorf("CreateReview addHeader err = %v, want nil", err)
+	}
+}
+
 func TestPullRequestsService_UpdateReview(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()
diff --git a/github/reactions_test.go b/github/reactions_test.go
index 031980c3..5bcad411 100644
--- a/github/reactions_test.go
+++ b/github/reactions_test.go
@@ -89,7 +89,7 @@ func TestReactionsService_ListCommentReactions(t *testing.T) {
 
 	const methodName = "ListCommentReactions"
 	testBadOptions(t, methodName, func() (err error) {
-		_, _, err = client.Reactions.ListCommentReactions(ctx, "\n", "\n", 1, opt)
+		_, _, err = client.Reactions.ListCommentReactions(ctx, "\n", "\n", -1, opt)
 		return err
 	})
 
@@ -126,7 +126,7 @@ func TestReactionsService_CreateCommentReaction(t *testing.T) {
 
 	const methodName = "CreateCommentReaction"
 	testBadOptions(t, methodName, func() (err error) {
-		_, _, err = client.Reactions.CreateCommentReaction(ctx, "\n", "\n", 1, "+1")
+		_, _, err = client.Reactions.CreateCommentReaction(ctx, "\n", "\n", -1, "\n")
 		return err
 	})
 
@@ -160,10 +160,17 @@ func TestReactionsService_ListIssueReactions(t *testing.T) {
 	if !reflect.DeepEqual(got, want) {
 		t.Errorf("ListIssueReactions = %+v, want %+v", got, want)
 	}
+}
+
+func TestReactionsService_ListIssueReactions_coverage(t *testing.T) {
+	client, _, _, teardown := setup()
+	defer teardown()
+
+	ctx := context.Background()
 
 	const methodName = "ListIssueReactions"
 	testBadOptions(t, methodName, func() (err error) {
-		_, _, err = client.Reactions.ListIssueReactions(ctx, "\n", "\n", 1, nil)
+		_, _, err = client.Reactions.ListIssueReactions(ctx, "\n", "\n", -1, &ListOptions{})
 		return err
 	})
 
@@ -200,7 +207,7 @@ func TestReactionsService_CreateIssueReaction(t *testing.T) {
 
 	const methodName = "CreateIssueReaction"
 	testBadOptions(t, methodName, func() (err error) {
-		_, _, err = client.Reactions.CreateIssueReaction(ctx, "\n", "\n", 1, "+1")
+		_, _, err = client.Reactions.CreateIssueReaction(ctx, "\n", "\n", -1, "\n")
 		return err
 	})
 
@@ -234,10 +241,17 @@ func TestReactionsService_ListIssueCommentReactions(t *testing.T) {
 	if !reflect.DeepEqual(got, want) {
 		t.Errorf("ListIssueCommentReactions = %+v, want %+v", got, want)
 	}
+}
+
+func TestReactionsService_ListIssueCommentReactions_coverage(t *testing.T) {
+	client, _, _, teardown := setup()
+	defer teardown()
+
+	ctx := context.Background()
 
 	const methodName = "ListIssueCommentReactions"
 	testBadOptions(t, methodName, func() (err error) {
-		_, _, err = client.Reactions.ListIssueCommentReactions(ctx, "\n", "\n", 1, nil)
+		_, _, err = client.Reactions.ListIssueCommentReactions(ctx, "\n", "\n", -1, &ListOptions{})
 		return err
 	})
 
@@ -274,7 +288,7 @@ func TestReactionsService_CreateIssueCommentReaction(t *testing.T) {
 
 	const methodName = "CreateIssueCommentReaction"
 	testBadOptions(t, methodName, func() (err error) {
-		_, _, err = client.Reactions.CreateIssueCommentReaction(ctx, "\n", "\n", 1, "+1")
+		_, _, err = client.Reactions.CreateIssueCommentReaction(ctx, "\n", "\n", -1, "\n")
 		return err
 	})
 
@@ -308,10 +322,17 @@ func TestReactionsService_ListPullRequestCommentReactions(t *testing.T) {
 	if !reflect.DeepEqual(got, want) {
 		t.Errorf("ListPullRequestCommentReactions = %+v, want %+v", got, want)
 	}
+}
+
+func TestReactionsService_ListPullRequestCommentReactions_coverage(t *testing.T) {
+	client, _, _, teardown := setup()
+	defer teardown()
+
+	ctx := context.Background()
 
 	const methodName = "ListPullRequestCommentReactions"
 	testBadOptions(t, methodName, func() (err error) {
-		_, _, err = client.Reactions.ListPullRequestCommentReactions(ctx, "\n", "\n", 1, nil)
+		_, _, err = client.Reactions.ListPullRequestCommentReactions(ctx, "\n", "\n", -1, &ListOptions{})
 		return err
 	})
 
@@ -348,7 +369,7 @@ func TestReactionsService_CreatePullRequestCommentReaction(t *testing.T) {
 
 	const methodName = "CreatePullRequestCommentReaction"
 	testBadOptions(t, methodName, func() (err error) {
-		_, _, err = client.Reactions.CreatePullRequestCommentReaction(ctx, "\n", "\n", 1, "+1")
+		_, _, err = client.Reactions.CreatePullRequestCommentReaction(ctx, "\n", "\n", -1, "\n")
 		return err
 	})
 
@@ -382,10 +403,17 @@ func TestReactionsService_ListTeamDiscussionReactions(t *testing.T) {
 	if !reflect.DeepEqual(got, want) {
 		t.Errorf("ListTeamDiscussionReactions = %+v, want %+v", got, want)
 	}
+}
+
+func TestReactionsService_ListTeamDiscussionReactions_coverage(t *testing.T) {
+	client, _, _, teardown := setup()
+	defer teardown()
+
+	ctx := context.Background()
 
 	const methodName = "ListTeamDiscussionReactions"
 	testBadOptions(t, methodName, func() (err error) {
-		_, _, err = client.Reactions.ListTeamDiscussionReactions(ctx, -1, -2, nil)
+		_, _, err = client.Reactions.ListTeamDiscussionReactions(ctx, -1, -2, &ListOptions{})
 		return err
 	})
 
@@ -456,12 +484,27 @@ func TestReactionService_ListTeamDiscussionCommentReactions(t *testing.T) {
 	if !reflect.DeepEqual(got, want) {
 		t.Errorf("ListTeamDiscussionCommentReactions = %+v, want %+v", got, want)
 	}
+}
+
+func TestReactionService_ListTeamDiscussionCommentReactions_coverage(t *testing.T) {
+	client, _, _, teardown := setup()
+	defer teardown()
+
+	ctx := context.Background()
 
 	const methodName = "ListTeamDiscussionCommentReactions"
 	testBadOptions(t, methodName, func() (err error) {
-		_, _, err = client.Reactions.ListTeamDiscussionCommentReactions(ctx, -1, -2, -3, nil)
+		_, _, err = client.Reactions.ListTeamDiscussionCommentReactions(ctx, -1, -2, -3, &ListOptions{})
 		return err
 	})
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		got, resp, err := client.Reactions.ListTeamDiscussionCommentReactions(ctx, 1, 2, 3, nil)
+		if got != nil {
+			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
+		}
+		return resp, err
+	})
 }
 
 func TestReactionService_CreateTeamDiscussionCommentReaction(t *testing.T) {
diff --git a/github/repos_test.go b/github/repos_test.go
index 4dafeb25..aaa517c5 100644
--- a/github/repos_test.go
+++ b/github/repos_test.go
@@ -706,6 +706,14 @@ func TestRepositoriesService_ListContributors(t *testing.T) {
 		_, _, err = client.Repositories.ListContributors(ctx, "\n", "\n", opts)
 		return err
 	})
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		got, resp, err := client.Repositories.ListContributors(ctx, "o", "r", opts)
+		if got != nil {
+			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
+		}
+		return resp, err
+	})
 }
 
 func TestRepositoriesService_ListLanguages(t *testing.T) {
@@ -2063,6 +2071,14 @@ func TestRepositoriesService_ReplaceAppRestrictions(t *testing.T) {
 		_, _, err = client.Repositories.ReplaceAppRestrictions(ctx, "\n", "\n", "\n", input)
 		return err
 	})
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		got, resp, err := client.Repositories.ReplaceAppRestrictions(ctx, "o", "r", "b", input)
+		if got != nil {
+			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
+		}
+		return resp, err
+	})
 }
 
 func TestRepositoriesService_AddAppRestrictions(t *testing.T) {
@@ -2093,6 +2109,14 @@ func TestRepositoriesService_AddAppRestrictions(t *testing.T) {
 		_, _, err = client.Repositories.AddAppRestrictions(ctx, "\n", "\n", "\n", input)
 		return err
 	})
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		got, resp, err := client.Repositories.AddAppRestrictions(ctx, "o", "r", "b", input)
+		if got != nil {
+			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
+		}
+		return resp, err
+	})
 }
 
 func TestRepositoriesService_RemoveAppRestrictions(t *testing.T) {
@@ -2119,6 +2143,14 @@ func TestRepositoriesService_RemoveAppRestrictions(t *testing.T) {
 		_, _, err = client.Repositories.RemoveAppRestrictions(ctx, "\n", "\n", "\n", input)
 		return err
 	})
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		got, resp, err := client.Repositories.RemoveAppRestrictions(ctx, "o", "r", "b", input)
+		if got != nil {
+			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
+		}
+		return resp, err
+	})
 }
 
 func TestRepositoriesService_Transfer(t *testing.T) {