Skip to content

Commit 77a6caa

Browse files
committed
test for all possible titles
1 parent 945d4ff commit 77a6caa

File tree

3 files changed

+286
-2
lines changed

3 files changed

+286
-2
lines changed

command/common.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func getTitle(cmd *cobra.Command, cmdType string, matchCount int, totalMatchCoun
2020
}
2121
})
2222

23-
title := "\n%s in %s\n\n"
2423
if totalMatchCount == 0 {
24+
title := "\n%s in %s\n\n"
2525
msg := fmt.Sprintf("There are no open %ss", cmdType)
2626

2727
if userSetFlagCounter > 0 {
@@ -30,7 +30,7 @@ func getTitle(cmd *cobra.Command, cmdType string, matchCount int, totalMatchCoun
3030
return fmt.Sprintf(title, msg, ghrepo.FullName(baseRepo))
3131
}
3232

33-
title = "\nShowing %d of %s in %s"
33+
title := "\nShowing %d of %s in %s"
3434
if (!limitSet && userSetFlagCounter > 0) || (userSetFlagCounter > 1) {
3535
matchStr := "match"
3636
if totalMatchCount == 1 {

command/issue_test.go

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,149 @@ Showing 3 of 3 issues in OWNER/REPO
129129
}
130130
}
131131

132+
func TestIssueList_limit(t *testing.T) {
133+
initBlankContext("OWNER/REPO", "master")
134+
http := initFakeHTTP()
135+
http.StubRepoResponse("OWNER", "REPO")
136+
137+
jsonFile, _ := os.Open("../test/fixtures/issueList.json")
138+
defer jsonFile.Close()
139+
http.StubResponse(200, jsonFile)
140+
141+
output, err := RunCommand(issueListCmd, "issue list -L 10")
142+
if err != nil {
143+
t.Fatal(err)
144+
}
145+
146+
eq(t, output.Stderr(), `
147+
Showing 3 of 3 issues in OWNER/REPO
148+
149+
`)
150+
}
151+
152+
func TestIssueList_smallLimit(t *testing.T) {
153+
initBlankContext("OWNER/REPO", "master")
154+
http := initFakeHTTP()
155+
http.StubRepoResponse("OWNER", "REPO")
156+
157+
jsonFile, _ := os.Open("../test/fixtures/issueList.json")
158+
defer jsonFile.Close()
159+
http.StubResponse(200, jsonFile)
160+
161+
output, err := RunCommand(issueListCmd, "issue list -L 2")
162+
if err != nil {
163+
t.Fatal(err)
164+
}
165+
166+
eq(t, output.Stderr(), `
167+
Showing 2 of 3 issues in OWNER/REPO
168+
169+
`)
170+
}
171+
172+
func TestIssueList_multipleFilterWithLimit(t *testing.T) {
173+
initBlankContext("OWNER/REPO", "master")
174+
http := initFakeHTTP()
175+
http.StubRepoResponse("OWNER", "REPO")
176+
177+
jsonFile, _ := os.Open("../test/fixtures/issueList.json")
178+
defer jsonFile.Close()
179+
http.StubResponse(200, jsonFile)
180+
181+
output, err := RunCommand(issueListCmd, "issue list -s open -l web -L 2")
182+
if err != nil {
183+
t.Fatal(err)
184+
}
185+
186+
eq(t, output.Stderr(), `
187+
Showing 2 of 3 issues in OWNER/REPO that match your search
188+
189+
`)
190+
}
191+
192+
func TestIssueList_multipleFilterWithoutLimit(t *testing.T) {
193+
initBlankContext("OWNER/REPO", "master")
194+
http := initFakeHTTP()
195+
http.StubRepoResponse("OWNER", "REPO")
196+
197+
jsonFile, _ := os.Open("../test/fixtures/issueList.json")
198+
defer jsonFile.Close()
199+
http.StubResponse(200, jsonFile)
200+
201+
output, err := RunCommand(issueListCmd, "issue list -s open -l web")
202+
if err != nil {
203+
t.Fatal(err)
204+
}
205+
206+
eq(t, output.Stderr(), `
207+
Showing 3 of 3 issues in OWNER/REPO that match your search
208+
209+
`)
210+
}
211+
212+
func TestIssueList_singleFilter(t *testing.T) {
213+
initBlankContext("OWNER/REPO", "master")
214+
http := initFakeHTTP()
215+
http.StubRepoResponse("OWNER", "REPO")
216+
217+
jsonFile, _ := os.Open("../test/fixtures/issueList.json")
218+
defer jsonFile.Close()
219+
http.StubResponse(200, jsonFile)
220+
221+
output, err := RunCommand(issueListCmd, "issue list -s open")
222+
if err != nil {
223+
t.Fatal(err)
224+
}
225+
226+
eq(t, output.Stderr(), `
227+
Showing 3 of 3 issues in OWNER/REPO that match your search
228+
229+
`)
230+
}
231+
232+
func TestIssueList_singleResultWithFilter(t *testing.T) {
233+
initBlankContext("OWNER/REPO", "master")
234+
http := initFakeHTTP()
235+
http.StubRepoResponse("OWNER", "REPO")
236+
237+
respBody := bytes.NewBufferString(`{
238+
"data": {
239+
"repository": {
240+
"hasIssuesEnabled": true,
241+
"issues": {
242+
"totalCount": 1,
243+
"nodes": [
244+
{
245+
"number": 1,
246+
"title": "number won",
247+
"url": "https://wow.com",
248+
"labels": {
249+
"nodes": [
250+
{
251+
"name": "label"
252+
}
253+
],
254+
"totalCount": 1
255+
}
256+
}
257+
]
258+
}
259+
}
260+
}
261+
}`)
262+
http.StubResponse(200, respBody)
263+
264+
output, err := RunCommand(issueListCmd, "issue list -s open")
265+
if err != nil {
266+
t.Fatal(err)
267+
}
268+
269+
eq(t, output.Stderr(), `
270+
Showing 1 of 1 issue in OWNER/REPO that matches your search
271+
272+
`)
273+
}
274+
132275
func TestIssueList_withFlags(t *testing.T) {
133276
initBlankContext("OWNER/REPO", "master")
134277
http := initFakeHTTP()

command/pr_test.go

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,147 @@ Showing 3 of 3 pull requests in OWNER/REPO
181181
`)
182182
}
183183

184+
func TestPRList_limit(t *testing.T) {
185+
initBlankContext("OWNER/REPO", "master")
186+
http := initFakeHTTP()
187+
http.StubRepoResponse("OWNER", "REPO")
188+
189+
jsonFile, _ := os.Open("../test/fixtures/prList.json")
190+
defer jsonFile.Close()
191+
http.StubResponse(200, jsonFile)
192+
193+
output, err := RunCommand(prListCmd, "pr list -L 10")
194+
if err != nil {
195+
t.Fatal(err)
196+
}
197+
198+
eq(t, output.Stderr(), `
199+
Showing 3 of 3 pull requests in OWNER/REPO
200+
201+
`)
202+
}
203+
204+
func TestPRList_smallLimit(t *testing.T) {
205+
initBlankContext("OWNER/REPO", "master")
206+
http := initFakeHTTP()
207+
http.StubRepoResponse("OWNER", "REPO")
208+
209+
jsonFile, _ := os.Open("../test/fixtures/prList.json")
210+
defer jsonFile.Close()
211+
http.StubResponse(200, jsonFile)
212+
213+
output, err := RunCommand(prListCmd, "pr list -L 2")
214+
if err != nil {
215+
t.Fatal(err)
216+
}
217+
218+
eq(t, output.Stderr(), `
219+
Showing 2 of 3 pull requests in OWNER/REPO
220+
221+
`)
222+
}
223+
224+
func TestPRList_multipleFilterWithLimit(t *testing.T) {
225+
initBlankContext("OWNER/REPO", "master")
226+
http := initFakeHTTP()
227+
http.StubRepoResponse("OWNER", "REPO")
228+
229+
jsonFile, _ := os.Open("../test/fixtures/prList.json")
230+
defer jsonFile.Close()
231+
http.StubResponse(200, jsonFile)
232+
233+
output, err := RunCommand(prListCmd, "pr list -s open -l one -L 2")
234+
if err != nil {
235+
t.Fatal(err)
236+
}
237+
238+
eq(t, output.Stderr(), `
239+
Showing 2 of 3 pull requests in OWNER/REPO that match your search
240+
241+
`)
242+
}
243+
244+
func TestPRList_multipleFilterWithoutLimit(t *testing.T) {
245+
initBlankContext("OWNER/REPO", "master")
246+
http := initFakeHTTP()
247+
http.StubRepoResponse("OWNER", "REPO")
248+
249+
jsonFile, _ := os.Open("../test/fixtures/prList.json")
250+
defer jsonFile.Close()
251+
http.StubResponse(200, jsonFile)
252+
253+
output, err := RunCommand(prListCmd, "pr list -s open -l one")
254+
if err != nil {
255+
t.Fatal(err)
256+
}
257+
258+
eq(t, output.Stderr(), `
259+
Showing 3 of 3 pull requests in OWNER/REPO that match your search
260+
261+
`)
262+
}
263+
264+
func TestPRList_singleFilter(t *testing.T) {
265+
initBlankContext("OWNER/REPO", "master")
266+
http := initFakeHTTP()
267+
http.StubRepoResponse("OWNER", "REPO")
268+
269+
jsonFile, _ := os.Open("../test/fixtures/prList.json")
270+
defer jsonFile.Close()
271+
http.StubResponse(200, jsonFile)
272+
273+
output, err := RunCommand(prListCmd, "pr list -s open")
274+
if err != nil {
275+
t.Fatal(err)
276+
}
277+
278+
eq(t, output.Stderr(), `
279+
Showing 3 of 3 pull requests in OWNER/REPO that match your search
280+
281+
`)
282+
}
283+
284+
func TestPRList_singleResultWithFilter(t *testing.T) {
285+
initBlankContext("OWNER/REPO", "master")
286+
http := initFakeHTTP()
287+
http.StubRepoResponse("OWNER", "REPO")
288+
289+
respBody := bytes.NewBufferString(`{
290+
"data": {
291+
"repository": {
292+
"pullRequests": {
293+
"totalCount": 1,
294+
"edges": [
295+
{
296+
"node": {
297+
"number": 32,
298+
"title": "New feature",
299+
"url": "https://github.com/monalisa/hello/pull/32",
300+
"headRefName": "feature"
301+
}
302+
}
303+
],
304+
"pageInfo": {
305+
"hasNextPage": false,
306+
"endCursor": ""
307+
}
308+
}
309+
}
310+
}
311+
}`)
312+
http.StubResponse(200, respBody)
313+
314+
output, err := RunCommand(prListCmd, "pr list -s open -B develop")
315+
if err != nil {
316+
t.Fatal(err)
317+
}
318+
319+
eq(t, output.Stderr(), `
320+
Showing 1 of 1 pull request in OWNER/REPO that matches your search
321+
322+
`)
323+
}
324+
184325
func TestPRList_filtering(t *testing.T) {
185326
initBlankContext("OWNER/REPO", "master")
186327
http := initFakeHTTP()

0 commit comments

Comments
 (0)