forked from google/go-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pulls_reviewers_test.go
104 lines (89 loc) · 3.11 KB
/
pulls_reviewers_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright 2017 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"context"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestRequestReviewers(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/pulls/1/requested_reviewers", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testBody(t, r, `{"reviewers":["octocat","googlebot"],"team_reviewers":["justice-league","injustice-league"]}`+"\n")
testHeader(t, r, "Accept", mediaTypeTeamReviewPreview)
fmt.Fprint(w, `{"number":1}`)
})
// This returns a PR, unmarshalling of which is tested elsewhere
pull, _, err := client.PullRequests.RequestReviewers(context.Background(), "o", "r", 1, ReviewersRequest{Reviewers: []string{"octocat", "googlebot"}, TeamReviewers: []string{"justice-league", "injustice-league"}})
if err != nil {
t.Errorf("PullRequests.RequestReviewers returned error: %v", err)
}
want := &PullRequest{Number: Int(1)}
if !reflect.DeepEqual(pull, want) {
t.Errorf("PullRequests.RequestReviewers returned %+v, want %+v", pull, want)
}
}
func TestRemoveReviewers(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/pulls/1/requested_reviewers", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
testHeader(t, r, "Accept", mediaTypeTeamReviewPreview)
testBody(t, r, `{"reviewers":["octocat","googlebot"],"team_reviewers":["justice-league"]}`+"\n")
})
_, err := client.PullRequests.RemoveReviewers(context.Background(), "o", "r", 1, ReviewersRequest{Reviewers: []string{"octocat", "googlebot"}, TeamReviewers: []string{"justice-league"}})
if err != nil {
t.Errorf("PullRequests.RemoveReviewers returned error: %v", err)
}
}
func TestListReviewers(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/pulls/1/requested_reviewers", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeTeamReviewPreview)
fmt.Fprint(w, `{"users":[{"login":"octocat","id":1}],"teams":[{"id":1,"name":"Justice League"}]}`)
})
reviewers, _, err := client.PullRequests.ListReviewers(context.Background(), "o", "r", 1, nil)
if err != nil {
t.Errorf("PullRequests.ListReviewers returned error: %v", err)
}
want := &Reviewers{
Users: []*User{
{
Login: String("octocat"),
ID: Int(1),
},
},
Teams: []*Team{
{
ID: Int(1),
Name: String("Justice League"),
},
},
}
if !reflect.DeepEqual(reviewers, want) {
t.Errorf("PullRequests.ListReviewers returned %+v, want %+v", reviewers, want)
}
}
func TestListReviewers_withOptions(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/pulls/1/requested_reviewers", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{
"page": "2",
})
fmt.Fprint(w, `{}`)
})
_, _, err := client.PullRequests.ListReviewers(context.Background(), "o", "r", 1, &ListOptions{Page: 2})
if err != nil {
t.Errorf("PullRequests.ListReviewers returned error: %v", err)
}
}