@@ -620,15 +620,15 @@ func TestIssueService_DeleteLink(t *testing.T) {
620620func TestIssueService_Search (t * testing.T ) {
621621 setup ()
622622 defer teardown ()
623- testMux .HandleFunc ("/rest/api/2 /search" , func (w http.ResponseWriter , r * http.Request ) {
623+ testMux .HandleFunc ("/rest/api/3 /search/jql " , func (w http.ResponseWriter , r * http.Request ) {
624624 testMethod (t , r , http .MethodGet )
625- testRequestURL (t , r , "/rest/api/2 /search?expand=foo&jql=type+%3D+Bug+and+Status+NOT+IN+%28Resolved%29&maxResults=40&startAt=1 " )
625+ testRequestURL (t , r , "/rest/api/3 /search/jql ?expand=foo&jql=type+%3D+Bug+and+Status+NOT+IN+%28Resolved%29&maxResults=40" )
626626 w .WriteHeader (http .StatusOK )
627- 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}}}] }` )
627+ fmt .Fprint (w , `{"issues": [{"id": "10068"},{" id": "10067"},{" id": "10066"}],"nextPageToken ": "CAEaAggD" }` )
628628 })
629629
630- opt := & SearchOptions {StartAt : 1 , MaxResults : 40 , Expand : "foo" }
631- _ , resp , err := testClient .Issue .Search (context .Background (), "type = Bug and Status NOT IN (Resolved)" , opt )
630+ opt := & SearchOptions {MaxResults : 40 , Expand : "foo" }
631+ issues , resp , err := testClient .Issue .Search (context .Background (), "type = Bug and Status NOT IN (Resolved)" , opt )
632632
633633 if resp == nil {
634634 t .Errorf ("Response given: %+v" , resp )
@@ -637,29 +637,31 @@ func TestIssueService_Search(t *testing.T) {
637637 t .Errorf ("Error given: %s" , err )
638638 }
639639
640- if resp . StartAt != 1 {
641- t .Errorf ("StartAt should populate with 1, %v given " , resp . StartAt )
640+ if len ( issues ) != 3 {
641+ t .Errorf ("Expected 3 issues, got %d " , len ( issues ) )
642642 }
643- if resp .MaxResults != 40 {
644- t .Errorf ("MaxResults should populate with 40, %v given" , resp .MaxResults )
643+
644+ if resp .NextPageToken != "CAEaAggD" {
645+ t .Errorf ("NextPageToken should be 'CAEaAggD', got %v" , resp .NextPageToken )
645646 }
646- if resp .Total != 6 {
647- t .Errorf ("Total should populate with 6, %v given" , resp .Total )
647+
648+ if resp .IsLast != false {
649+ t .Errorf ("IsLast should be false when nextPageToken is present, got %v" , resp .IsLast )
648650 }
649651}
650652
651653func TestIssueService_SearchEmptyJQL (t * testing.T ) {
652654 setup ()
653655 defer teardown ()
654- testMux .HandleFunc ("/rest/api/2 /search" , func (w http.ResponseWriter , r * http.Request ) {
656+ testMux .HandleFunc ("/rest/api/3 /search/jql " , func (w http.ResponseWriter , r * http.Request ) {
655657 testMethod (t , r , http .MethodGet )
656- testRequestURL (t , r , "/rest/api/2 /search?expand=foo&maxResults=40&startAt=1 " )
658+ testRequestURL (t , r , "/rest/api/3 /search/jql ?expand=foo&maxResults=40" )
657659 w .WriteHeader (http .StatusOK )
658- 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}}}] }` )
660+ fmt .Fprint (w , `{"issues": [{"id": "10230"},{" id": "10004"}],"isLast ": true }` )
659661 })
660662
661- opt := & SearchOptions {StartAt : 1 , MaxResults : 40 , Expand : "foo" }
662- _ , resp , err := testClient .Issue .Search (context .Background (), "" , opt )
663+ opt := & SearchOptions {MaxResults : 40 , Expand : "foo" }
664+ issues , resp , err := testClient .Issue .Search (context .Background (), "" , opt )
663665
664666 if resp == nil {
665667 t .Errorf ("Response given: %+v" , resp )
@@ -668,25 +670,23 @@ func TestIssueService_SearchEmptyJQL(t *testing.T) {
668670 t .Errorf ("Error given: %s" , err )
669671 }
670672
671- if resp .StartAt != 1 {
672- t .Errorf ("StartAt should populate with 1, %v given" , resp .StartAt )
673- }
674- if resp .MaxResults != 40 {
675- t .Errorf ("StartAt should populate with 40, %v given" , resp .MaxResults )
673+ if len (issues ) != 2 {
674+ t .Errorf ("Expected 2 issues, got %d" , len (issues ))
676675 }
677- if resp .Total != 6 {
678- t .Errorf ("StartAt should populate with 6, %v given" , resp .Total )
676+
677+ if resp .IsLast != true {
678+ t .Errorf ("IsLast should be true when no nextPageToken, got %v" , resp .IsLast )
679679 }
680680}
681681
682682func TestIssueService_Search_WithoutPaging (t * testing.T ) {
683683 setup ()
684684 defer teardown ()
685- testMux .HandleFunc ("/rest/api/2 /search" , func (w http.ResponseWriter , r * http.Request ) {
685+ testMux .HandleFunc ("/rest/api/3 /search/jql " , func (w http.ResponseWriter , r * http.Request ) {
686686 testMethod (t , r , http .MethodGet )
687- testRequestURL (t , r , "/rest/api/2 /search?jql=something" )
687+ testRequestURL (t , r , "/rest/api/3 /search/jql ?jql=something" )
688688 w .WriteHeader (http .StatusOK )
689- fmt .Fprint (w , `{"expand": "schema,names","startAt": 0,"maxResults": 50,"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}}}] }` )
689+ fmt .Fprint (w , `{"issues": [{"id": "10230"},{" id": "10004"}],"isLast ": true }` )
690690 })
691691 _ , resp , err := testClient .Issue .Search (context .Background (), "something" , nil )
692692
@@ -697,40 +697,37 @@ func TestIssueService_Search_WithoutPaging(t *testing.T) {
697697 t .Errorf ("Error given: %s" , err )
698698 }
699699
700- if resp .StartAt != 0 {
701- t .Errorf ("StartAt should populate with 0, %v given" , resp .StartAt )
702- }
703- if resp .MaxResults != 50 {
704- t .Errorf ("StartAt should populate with 50, %v given" , resp .MaxResults )
700+ if ! resp .IsLast {
701+ t .Errorf ("IsLast should populate with true, %v given" , resp .IsLast )
705702 }
706- if resp .Total != 6 {
707- t .Errorf ("StartAt should populate with 6 , %v given" , resp .Total )
703+ if resp .NextPageToken != "" {
704+ t .Errorf ("NextPageToken should be empty when isLast=true , %v given" , resp .NextPageToken )
708705 }
709706}
710707
711708func TestIssueService_SearchPages (t * testing.T ) {
712709 setup ()
713710 defer teardown ()
714- testMux .HandleFunc ("/rest/api/2 /search" , func (w http.ResponseWriter , r * http.Request ) {
711+ testMux .HandleFunc ("/rest/api/3 /search/jql " , func (w http.ResponseWriter , r * http.Request ) {
715712 testMethod (t , r , http .MethodGet )
716- if r .URL .String () == "/rest/api/2 /search?expand=foo&jql=something&maxResults=2&startAt=1&validateQuery=warn " {
713+ if r .URL .String () == "/rest/api/3 /search/jql ?expand=foo&jql=something&maxResults=2" {
717714 w .WriteHeader (http .StatusOK )
718- 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}}}] }` )
715+ fmt .Fprint (w , `{"issues": [{"id": "10001"},{" id": "10002"}],"nextPageToken ": "page2token" }` )
719716 return
720- } else if r .URL .String () == "/rest/api/2 /search?expand=foo&jql=something&maxResults=2&startAt=3&validateQuery=warn " {
717+ } else if r .URL .String () == "/rest/api/3 /search/jql ?expand=foo&jql=something&maxResults=2&nextPageToken=page2token " {
721718 w .WriteHeader (http .StatusOK )
722- 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}}}] }` )
719+ fmt .Fprint (w , `{"issues": [{"id": "10003"},{" id": "10004"}],"nextPageToken ": "page3token" }` )
723720 return
724- } else if r .URL .String () == "/rest/api/2 /search?expand=foo&jql=something&maxResults=2&startAt=5&validateQuery=warn " {
721+ } else if r .URL .String () == "/rest/api/3 /search/jql ?expand=foo&jql=something&maxResults=2&nextPageToken=page3token " {
725722 w .WriteHeader (http .StatusOK )
726- 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}}] }` )
723+ fmt .Fprint (w , `{"issues": [{"id": "10005"}],"isLast ": true }` )
727724 return
728725 }
729726
730727 t .Errorf ("Unexpected URL: %v" , r .URL )
731728 })
732729
733- opt := & SearchOptions {StartAt : 1 , MaxResults : 2 , Expand : "foo" , ValidateQuery : "warn " }
730+ opt := & SearchOptions {MaxResults : 2 , Expand : "foo" }
734731 issues := make ([]Issue , 0 )
735732 err := testClient .Issue .SearchPages (context .Background (), "something" , opt , func (issue Issue ) error {
736733 issues = append (issues , issue )
@@ -749,19 +746,19 @@ func TestIssueService_SearchPages(t *testing.T) {
749746func TestIssueService_SearchPages_EmptyResult (t * testing.T ) {
750747 setup ()
751748 defer teardown ()
752- testMux .HandleFunc ("/rest/api/2 /search" , func (w http.ResponseWriter , r * http.Request ) {
749+ testMux .HandleFunc ("/rest/api/3 /search/jql " , func (w http.ResponseWriter , r * http.Request ) {
753750 testMethod (t , r , http .MethodGet )
754- if r .URL .String () == "/rest/api/2 /search?expand=foo&jql=something&maxResults=50&startAt=1&validateQuery=warn " {
751+ if r .URL .String () == "/rest/api/3 /search/jql ?expand=foo&jql=something&maxResults=50" {
755752 w .WriteHeader (http .StatusOK )
756- // This is what Jira outputs when the &maxResult= issue occurs. It used to cause SearchPages to go into an endless loop .
757- fmt .Fprint (w , `{"expand ": "schema,names","startAt": 0,"maxResults": 0,"total": 6,"issues": [] }` )
753+ // This is what Jira outputs for empty results in API v3. This test ensures SearchPages handles empty results correctly .
754+ fmt .Fprint (w , `{"issues ": [],"isLast": true }` )
758755 return
759756 }
760757
761758 t .Errorf ("Unexpected URL: %v" , r .URL )
762759 })
763760
764- opt := & SearchOptions {StartAt : 1 , MaxResults : 50 , Expand : "foo" , ValidateQuery : "warn " }
761+ opt := & SearchOptions {MaxResults : 50 , Expand : "foo" }
765762 issues := make ([]Issue , 0 )
766763 err := testClient .Issue .SearchPages (context .Background (), "something" , opt , func (issue Issue ) error {
767764 issues = append (issues , issue )
@@ -772,6 +769,9 @@ func TestIssueService_SearchPages_EmptyResult(t *testing.T) {
772769 t .Errorf ("Error given: %s" , err )
773770 }
774771
772+ if len (issues ) != 0 {
773+ t .Errorf ("Expected 0 issues for empty result, %v given" , len (issues ))
774+ }
775775}
776776
777777func TestIssueService_GetCustomFields (t * testing.T ) {
0 commit comments