@@ -3,7 +3,6 @@ package client
33import (
44 "encoding/json"
55 "errors"
6- "fmt"
76 "io"
87 "net/http"
98 "net/http/httptest"
@@ -471,98 +470,6 @@ func TestExecuteAll_MissingDataField(t *testing.T) {
471470 }
472471}
473472
474- func TestExecuteAll_Truncated (t * testing.T ) {
475- srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
476- token := r .URL .Query ().Get ("token" )
477- switch token {
478- case "" :
479- w .WriteHeader (http .StatusOK )
480- _ , _ = w .Write ([]byte (paginationPageBody (0 , 2500 , "cursor_1" )))
481- case "cursor_1" :
482- w .WriteHeader (http .StatusOK )
483- _ , _ = w .Write ([]byte (paginationPageBody (2500 , 2500 , "cursor_2" )))
484- case "cursor_2" :
485- w .WriteHeader (http .StatusOK )
486- _ , _ = w .Write ([]byte (paginationPageBody (5000 , 2500 , "cursor_3" )))
487- case "cursor_3" :
488- w .WriteHeader (http .StatusOK )
489- _ , _ = w .Write ([]byte (paginationPageBody (7500 , 2500 , "cursor_4" )))
490- default :
491- t .Fatalf ("unexpected token %q" , token )
492- }
493- }))
494- defer srv .Close ()
495-
496- c := New ("key" , WithBaseURL (srv .URL ), WithHTTPClient (srv .Client ()))
497- spec := & command.Spec {
498- Endpoint : "/v3/videos" ,
499- Method : "GET" ,
500- Paginated : true ,
501- }
502- inv := & command.Invocation {PathParams : make (map [string ]string ), QueryParams : make (url.Values )}
503-
504- _ , err := c .ExecuteAll (spec , inv )
505- var truncErr * ErrPaginationTruncated
506- if ! errors .As (err , & truncErr ) {
507- t .Fatalf ("err = %T, want *ErrPaginationTruncated" , err )
508- }
509- if truncErr .Count != 10000 {
510- t .Fatalf ("Count = %d, want 10000" , truncErr .Count )
511- }
512- var parsed []map [string ]any
513- if err := json .Unmarshal (truncErr .Data , & parsed ); err != nil {
514- t .Fatalf ("truncErr.Data is not valid JSON array: %v" , err )
515- }
516- if len (parsed ) != 10000 {
517- t .Fatalf ("len(parsed) = %d, want 10000" , len (parsed ))
518- }
519- }
520-
521- func TestExecuteAll_ExactlyAtLimit (t * testing.T ) {
522- srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
523- token := r .URL .Query ().Get ("token" )
524- switch token {
525- case "" :
526- w .WriteHeader (http .StatusOK )
527- _ , _ = w .Write ([]byte (paginationPageBody (0 , 2000 , "cursor_1" )))
528- case "cursor_1" :
529- w .WriteHeader (http .StatusOK )
530- _ , _ = w .Write ([]byte (paginationPageBody (2000 , 2000 , "cursor_2" )))
531- case "cursor_2" :
532- w .WriteHeader (http .StatusOK )
533- _ , _ = w .Write ([]byte (paginationPageBody (4000 , 2000 , "cursor_3" )))
534- case "cursor_3" :
535- w .WriteHeader (http .StatusOK )
536- _ , _ = w .Write ([]byte (paginationPageBody (6000 , 2000 , "cursor_4" )))
537- case "cursor_4" :
538- w .WriteHeader (http .StatusOK )
539- _ , _ = w .Write ([]byte (paginationPageBody (8000 , 2000 , "" )))
540- default :
541- t .Fatalf ("unexpected token %q" , token )
542- }
543- }))
544- defer srv .Close ()
545-
546- c := New ("key" , WithBaseURL (srv .URL ), WithHTTPClient (srv .Client ()))
547- spec := & command.Spec {
548- Endpoint : "/v3/videos" ,
549- Method : "GET" ,
550- Paginated : true ,
551- }
552- inv := & command.Invocation {PathParams : make (map [string ]string ), QueryParams : make (url.Values )}
553-
554- result , err := c .ExecuteAll (spec , inv )
555- if err != nil {
556- t .Fatalf ("unexpected error: %v" , err )
557- }
558- var parsed []map [string ]any
559- if err := json .Unmarshal (result , & parsed ); err != nil {
560- t .Fatalf ("result is not valid JSON array: %v" , err )
561- }
562- if len (parsed ) != 10000 {
563- t .Fatalf ("len(parsed) = %d, want 10000" , len (parsed ))
564- }
565- }
566473
567474func TestExecute_MultipartUpload (t * testing.T ) {
568475 var gotContentType string
@@ -631,24 +538,6 @@ func TestExecute_MultipartUpload(t *testing.T) {
631538 }
632539}
633540
634- func paginationPageBody (start , count int , nextToken string ) string {
635- items := make ([]map [string ]any , 0 , count )
636- for i := 0 ; i < count ; i ++ {
637- items = append (items , map [string ]any {"id" : fmt .Sprintf ("v%d" , start + i )})
638- }
639-
640- body := map [string ]any {
641- "data" : items ,
642- }
643- if nextToken == "" {
644- body ["next_token" ] = nil
645- } else {
646- body ["next_token" ] = nextToken
647- }
648- raw , _ := json .Marshal (body )
649- return string (raw )
650- }
651-
652541func TestExecute_MultipartMissingFilePath (t * testing.T ) {
653542 c := New ("key" )
654543
0 commit comments