forked from google/go-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
issues_milestones_test.go
174 lines (137 loc) · 4.74 KB
/
issues_milestones_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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Copyright 2014 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"
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestIssuesService_ListMilestones(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/repos/o/r/milestones", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{
"state": "closed",
"sort": "due_date",
"direction": "asc",
"page": "2",
})
fmt.Fprint(w, `[{"number":1}]`)
})
opt := &MilestoneListOptions{"closed", "due_date", "asc", ListOptions{Page: 2}}
milestones, _, err := client.Issues.ListMilestones(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("IssuesService.ListMilestones returned error: %v", err)
}
want := []*Milestone{{Number: Int(1)}}
if !reflect.DeepEqual(milestones, want) {
t.Errorf("IssuesService.ListMilestones returned %+v, want %+v", milestones, want)
}
}
func TestIssuesService_ListMilestones_invalidOwner(t *testing.T) {
client, _, _, teardown := setup()
defer teardown()
_, _, err := client.Issues.ListMilestones(context.Background(), "%", "r", nil)
testURLParseError(t, err)
}
func TestIssuesService_GetMilestone(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/repos/o/r/milestones/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"number":1}`)
})
milestone, _, err := client.Issues.GetMilestone(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("IssuesService.GetMilestone returned error: %v", err)
}
want := &Milestone{Number: Int(1)}
if !reflect.DeepEqual(milestone, want) {
t.Errorf("IssuesService.GetMilestone returned %+v, want %+v", milestone, want)
}
}
func TestIssuesService_GetMilestone_invalidOwner(t *testing.T) {
client, _, _, teardown := setup()
defer teardown()
_, _, err := client.Issues.GetMilestone(context.Background(), "%", "r", 1)
testURLParseError(t, err)
}
func TestIssuesService_CreateMilestone(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
input := &Milestone{Title: String("t")}
mux.HandleFunc("/repos/o/r/milestones", func(w http.ResponseWriter, r *http.Request) {
v := new(Milestone)
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, `{"number":1}`)
})
milestone, _, err := client.Issues.CreateMilestone(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("IssuesService.CreateMilestone returned error: %v", err)
}
want := &Milestone{Number: Int(1)}
if !reflect.DeepEqual(milestone, want) {
t.Errorf("IssuesService.CreateMilestone returned %+v, want %+v", milestone, want)
}
}
func TestIssuesService_CreateMilestone_invalidOwner(t *testing.T) {
client, _, _, teardown := setup()
defer teardown()
_, _, err := client.Issues.CreateMilestone(context.Background(), "%", "r", nil)
testURLParseError(t, err)
}
func TestIssuesService_EditMilestone(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
input := &Milestone{Title: String("t")}
mux.HandleFunc("/repos/o/r/milestones/1", func(w http.ResponseWriter, r *http.Request) {
v := new(Milestone)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "PATCH")
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
fmt.Fprint(w, `{"number":1}`)
})
milestone, _, err := client.Issues.EditMilestone(context.Background(), "o", "r", 1, input)
if err != nil {
t.Errorf("IssuesService.EditMilestone returned error: %v", err)
}
want := &Milestone{Number: Int(1)}
if !reflect.DeepEqual(milestone, want) {
t.Errorf("IssuesService.EditMilestone returned %+v, want %+v", milestone, want)
}
}
func TestIssuesService_EditMilestone_invalidOwner(t *testing.T) {
client, _, _, teardown := setup()
defer teardown()
_, _, err := client.Issues.EditMilestone(context.Background(), "%", "r", 1, nil)
testURLParseError(t, err)
}
func TestIssuesService_DeleteMilestone(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/repos/o/r/milestones/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
})
_, err := client.Issues.DeleteMilestone(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("IssuesService.DeleteMilestone returned error: %v", err)
}
}
func TestIssuesService_DeleteMilestone_invalidOwner(t *testing.T) {
client, _, _, teardown := setup()
defer teardown()
_, err := client.Issues.DeleteMilestone(context.Background(), "%", "r", 1)
testURLParseError(t, err)
}