99 "encoding/json"
1010 "fmt"
1111 "net/http"
12- "strings "
12+ "net/url "
1313 "testing"
1414 "time"
1515
@@ -22,26 +22,13 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokens(t *testing.T)
2222
2323 mux .HandleFunc ("/orgs/o/personal-access-tokens" , func (w http.ResponseWriter , r * http.Request ) {
2424 testMethod (t , r , "GET" )
25- expectedQuery := map [ string ][] string {
25+ testFormValuesList ( t , r , url. Values {
2626 "per_page" : {"2" },
2727 "page" : {"2" },
2828 "sort" : {"created_at" },
2929 "direction" : {"desc" },
3030 "owner[]" : {"octocat" , "octodog" , "otherbot" },
31- }
32-
33- query := r .URL .Query ()
34- for key , expectedValues := range expectedQuery {
35- actualValues := query [key ]
36- if len (actualValues ) != len (expectedValues ) {
37- t .Errorf ("Expected %v values for query param %v, got %v" , len (expectedValues ), key , len (actualValues ))
38- }
39- for i , expectedValue := range expectedValues {
40- if actualValues [i ] != expectedValue {
41- t .Errorf ("Expected query param %v to be %v, got %v" , key , expectedValue , actualValues [i ])
42- }
43- }
44- }
31+ })
4532
4633 fmt .Fprint (w , `
4734 [
@@ -165,13 +152,8 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokens_ownerOnly(t *t
165152
166153 mux .HandleFunc ("/orgs/o/personal-access-tokens" , func (w http.ResponseWriter , r * http.Request ) {
167154 testMethod (t , r , "GET" )
168- // When only Owner is set, addOptions adds no query params, so URL gets "?" + owner[]=...
169- if ! strings .Contains (r .URL .RawQuery , "owner[]=" ) {
170- t .Errorf ("Expected query to contain owner[]=, got %q" , r .URL .RawQuery )
171- }
172- if strings .HasPrefix (r .URL .RawQuery , "&" ) {
173- t .Errorf ("Expected query to start with ?, got %q" , r .URL .RawQuery )
174- }
155+ testFormValues (t , r , values {"owner[]" : "octocat" })
156+
175157 fmt .Fprint (w , "[]" )
176158 })
177159
@@ -189,27 +171,14 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests(t *test
189171
190172 mux .HandleFunc ("/orgs/o/personal-access-token-requests" , func (w http.ResponseWriter , r * http.Request ) {
191173 testMethod (t , r , "GET" )
192- expectedQuery := map [ string ][] string {
174+ testFormValuesList ( t , r , url. Values {
193175 "per_page" : {"2" },
194176 "page" : {"2" },
195177 "sort" : {"created_at" },
196178 "direction" : {"desc" },
197179 "owner[]" : {"octocat" , "octodog" },
198180 "token_id[]" : {"11579703" , "11579704" },
199- }
200-
201- query := r .URL .Query ()
202- for key , expectedValues := range expectedQuery {
203- actualValues := query [key ]
204- if len (actualValues ) != len (expectedValues ) {
205- t .Errorf ("Expected %v values for query param %v, got %v" , len (expectedValues ), key , len (actualValues ))
206- }
207- for i , expectedValue := range expectedValues {
208- if actualValues [i ] != expectedValue {
209- t .Errorf ("Expected query param %v to be %v, got %v" , key , expectedValue , actualValues [i ])
210- }
211- }
212- }
181+ })
213182
214183 fmt .Fprint (w , `[
215184 {
@@ -331,13 +300,7 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests_ownerOn
331300
332301 mux .HandleFunc ("/orgs/o/personal-access-token-requests" , func (w http.ResponseWriter , r * http.Request ) {
333302 testMethod (t , r , "GET" )
334- // When only Owner is set (no ListOptions, TokenID, etc.), addOptions adds no query params, so URL gets "?" + owner[]=...
335- if ! strings .Contains (r .URL .RawQuery , "owner[]=" ) {
336- t .Errorf ("Expected query to contain owner[]=, got %q" , r .URL .RawQuery )
337- }
338- if strings .HasPrefix (r .URL .RawQuery , "&" ) {
339- t .Errorf ("Expected query to start with ?, got %q" , r .URL .RawQuery )
340- }
303+ testFormValues (t , r , values {"owner[]" : "octocat" })
341304 fmt .Fprint (w , "[]" )
342305 })
343306
@@ -357,13 +320,7 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests_tokenID
357320
358321 mux .HandleFunc ("/orgs/o/personal-access-token-requests" , func (w http.ResponseWriter , r * http.Request ) {
359322 testMethod (t , r , "GET" )
360- // When only TokenID is set (no Owner, ListOptions, etc.), addOptions adds no query params, so URL gets "?" + token_id[]=...
361- if ! strings .Contains (r .URL .RawQuery , "token_id[]=" ) {
362- t .Errorf ("Expected query to contain token_id[]=, got %q" , r .URL .RawQuery )
363- }
364- if strings .HasPrefix (r .URL .RawQuery , "&" ) {
365- t .Errorf ("Expected query not to start with & (token_id should be first param with ?), got %q" , r .URL .RawQuery )
366- }
323+ testFormValues (t , r , values {"token_id[]" : "11579703" })
367324 fmt .Fprint (w , "[]" )
368325 })
369326
0 commit comments