Repository: google/go-github
Pull request #1769 (2020-12-26 16:17:40)

Improve pulls_reviews.go coverage

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

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

```diff
@@            Coverage Diff             @@
##           master    #1769      +/-   ##
==========================================
+ Coverage   96.94%   97.03%   +0.09%     
==========================================
  Files          98       98              
  Lines        6373     6373              
==========================================
+ Hits         6178     6184       +6     
+ Misses        109      106       -3     
+ Partials       86       83       -3     
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/1769?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [github/pulls\_reviews.go](https://codecov.io/gh/google/go-github/pull/1769/diff?src=pr&el=tree#diff-Z2l0aHViL3B1bGxzX3Jldmlld3MuZ28=) | `100.00% <0.00%> (+5.66%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/go-github/pull/1769?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/1769?src=pr&el=footer). Last update [4489191...56c52ac](https://codecov.io/gh/google/go-github/pull/1769?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
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
 }


Test patch:
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) {