@@ -3,14 +3,15 @@ package jira
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
- "github.com/google/go-cmp/cmp"
7
6
"io"
8
7
"io/ioutil"
9
8
"net/http"
10
9
"reflect"
11
10
"strings"
12
11
"testing"
13
12
13
+ "github.com/google/go-cmp/cmp"
14
+
14
15
"time"
15
16
16
17
"github.com/trivago/tgo/tcontainer"
@@ -596,7 +597,7 @@ func TestIssueService_Search(t *testing.T) {
596
597
defer teardown ()
597
598
testMux .HandleFunc ("/rest/api/2/search" , func (w http.ResponseWriter , r * http.Request ) {
598
599
testMethod (t , r , "GET" )
599
- testRequestURL (t , r , "/rest/api/2/search?jql=something&startAt=1&maxResults=40&expand=foo" )
600
+ testRequestURL (t , r , "/rest/api/2/search?jql=something&startAt=1& maxResults=40&expand=foo" )
600
601
w .WriteHeader (http .StatusOK )
601
602
fmt .Fprint (w , `{"expand": "schema,names","startAt": 1,"maxResults": 40,"total": 6,"issues": [{"expand": "html","id": "10230","self": "http://kelpie9:8081/rest/api/2/issue/BULK-62","key": "BULK-62","fields": {"summary": "testing","timetracking": null,"issuetype": {"self": "http://kelpie9:8081/rest/api/2/issuetype/5","id": "5","description": "The sub-task of the issue","iconUrl": "http://kelpie9:8081/images/icons/issue_subtask.gif","name": "Sub-task","subtask": true},"customfield_10071": null}},{"expand": "html","id": "10004","self": "http://kelpie9:8081/rest/api/2/issue/BULK-47","key": "BULK-47","fields": {"summary": "Cheese v1 2.0 issue","timetracking": null,"issuetype": {"self": "http://kelpie9:8081/rest/api/2/issuetype/3","id": "3","description": "A task that needs to be done.","iconUrl": "http://kelpie9:8081/images/icons/task.gif","name": "Task","subtask": false}}}]}` )
602
603
})
@@ -657,15 +658,15 @@ func TestIssueService_SearchPages(t *testing.T) {
657
658
defer teardown ()
658
659
testMux .HandleFunc ("/rest/api/2/search" , func (w http.ResponseWriter , r * http.Request ) {
659
660
testMethod (t , r , "GET" )
660
- if r .URL .String () == "/rest/api/2/search?jql=something&startAt=1&maxResults=2&expand=foo&validateQuery=warn" {
661
+ if r .URL .String () == "/rest/api/2/search?jql=something&startAt=1& maxResults=2&expand=foo&validateQuery=warn" {
661
662
w .WriteHeader (http .StatusOK )
662
663
fmt .Fprint (w , `{"expand": "schema,names","startAt": 1,"maxResults": 2,"total": 6,"issues": [{"expand": "html","id": "10230","self": "http://kelpie9:8081/rest/api/2/issue/BULK-62","key": "BULK-62","fields": {"summary": "testing","timetracking": null,"issuetype": {"self": "http://kelpie9:8081/rest/api/2/issuetype/5","id": "5","description": "The sub-task of the issue","iconUrl": "http://kelpie9:8081/images/icons/issue_subtask.gif","name": "Sub-task","subtask": true},"customfield_10071": null}},{"expand": "html","id": "10004","self": "http://kelpie9:8081/rest/api/2/issue/BULK-47","key": "BULK-47","fields": {"summary": "Cheese v1 2.0 issue","timetracking": null,"issuetype": {"self": "http://kelpie9:8081/rest/api/2/issuetype/3","id": "3","description": "A task that needs to be done.","iconUrl": "http://kelpie9:8081/images/icons/task.gif","name": "Task","subtask": false}}}]}` )
663
664
return
664
- } else if r .URL .String () == "/rest/api/2/search?jql=something&startAt=3&maxResults=2&expand=foo&validateQuery=warn" {
665
+ } else if r .URL .String () == "/rest/api/2/search?jql=something&startAt=3& maxResults=2&expand=foo&validateQuery=warn" {
665
666
w .WriteHeader (http .StatusOK )
666
667
fmt .Fprint (w , `{"expand": "schema,names","startAt": 3,"maxResults": 2,"total": 6,"issues": [{"expand": "html","id": "10230","self": "http://kelpie9:8081/rest/api/2/issue/BULK-62","key": "BULK-62","fields": {"summary": "testing","timetracking": null,"issuetype": {"self": "http://kelpie9:8081/rest/api/2/issuetype/5","id": "5","description": "The sub-task of the issue","iconUrl": "http://kelpie9:8081/images/icons/issue_subtask.gif","name": "Sub-task","subtask": true},"customfield_10071": null}},{"expand": "html","id": "10004","self": "http://kelpie9:8081/rest/api/2/issue/BULK-47","key": "BULK-47","fields": {"summary": "Cheese v1 2.0 issue","timetracking": null,"issuetype": {"self": "http://kelpie9:8081/rest/api/2/issuetype/3","id": "3","description": "A task that needs to be done.","iconUrl": "http://kelpie9:8081/images/icons/task.gif","name": "Task","subtask": false}}}]}` )
667
668
return
668
- } else if r .URL .String () == "/rest/api/2/search?jql=something&startAt=5&maxResults=2&expand=foo&validateQuery=warn" {
669
+ } else if r .URL .String () == "/rest/api/2/search?jql=something&startAt=5& maxResults=2&expand=foo&validateQuery=warn" {
669
670
w .WriteHeader (http .StatusOK )
670
671
fmt .Fprint (w , `{"expand": "schema,names","startAt": 5,"maxResults": 2,"total": 6,"issues": [{"expand": "html","id": "10230","self": "http://kelpie9:8081/rest/api/2/issue/BULK-62","key": "BULK-62","fields": {"summary": "testing","timetracking": null,"issuetype": {"self": "http://kelpie9:8081/rest/api/2/issuetype/5","id": "5","description": "The sub-task of the issue","iconUrl": "http://kelpie9:8081/images/icons/issue_subtask.gif","name": "Sub-task","subtask": true},"customfield_10071": null}}]}` )
671
672
return
@@ -690,6 +691,34 @@ func TestIssueService_SearchPages(t *testing.T) {
690
691
}
691
692
}
692
693
694
+ func TestIssueService_SearchPages_EmptyResult (t * testing.T ) {
695
+ setup ()
696
+ defer teardown ()
697
+ testMux .HandleFunc ("/rest/api/2/search" , func (w http.ResponseWriter , r * http.Request ) {
698
+ testMethod (t , r , "GET" )
699
+ if r .URL .String () == "/rest/api/2/search?jql=something&startAt=1&maxResults=50&expand=foo&validateQuery=warn" {
700
+ w .WriteHeader (http .StatusOK )
701
+ // This is what Jira outputs when the &maxResult= issue occurs. It used to cause SearchPages to go into an endless loop.
702
+ fmt .Fprint (w , `{"expand": "schema,names","startAt": 0,"maxResults": 0,"total": 6,"issues": []}` )
703
+ return
704
+ }
705
+
706
+ t .Errorf ("Unexpected URL: %v" , r .URL )
707
+ })
708
+
709
+ opt := & SearchOptions {StartAt : 1 , MaxResults : 50 , Expand : "foo" , ValidateQuery : "warn" }
710
+ issues := make ([]Issue , 0 )
711
+ err := testClient .Issue .SearchPages ("something" , opt , func (issue Issue ) error {
712
+ issues = append (issues , issue )
713
+ return nil
714
+ })
715
+
716
+ if err != nil {
717
+ t .Errorf ("Error given: %s" , err )
718
+ }
719
+
720
+ }
721
+
693
722
func TestIssueService_GetCustomFields (t * testing.T ) {
694
723
setup ()
695
724
defer teardown ()
0 commit comments