@@ -513,152 +513,93 @@ func TestPaginationWithContextNilInput(t *testing.T) {
513
513
514
514
func TestPagination_Standalone (t * testing.T ) {
515
515
type testPageInput struct {
516
- NextToken string
516
+ NextToken * string
517
517
}
518
518
type testPageOutput struct {
519
- Value string
519
+ Value * string
520
520
NextToken * string
521
521
}
522
+ type testCase struct {
523
+ Value , PrevToken , NextToken * string
524
+ }
522
525
523
- expect := []struct {
524
- Value , PrevToken , NextToken string
525
- }{
526
- {"FirstValue" , "InitalToken" , "FirstToken" },
527
- {"SecondValue" , "FirstToken" , "SecondToken" },
528
- {"ThirdValue" , "SecondToken" , "" },
529
- }
530
- input := testPageInput {
531
- NextToken : expect [0 ].PrevToken ,
532
- }
533
-
534
- c := awstesting .NewClient (unit .Config ())
535
- i := 0
536
- p := aws.Pagination {
537
- NewRequest : func () (* aws.Request , error ) {
538
- r := c .NewRequest (
539
- & aws.Operation {
540
- Name : "Operation" ,
541
- Paginator : & aws.Paginator {
542
- InputTokens : []string {"NextToken" },
543
- OutputTokens : []string {"NextToken" },
544
- },
545
- },
546
- & input , & testPageOutput {},
547
- )
548
- // Setup handlers for testing
549
- r .Handlers .Clear ()
550
- r .Handlers .Build .PushBack (func (req * aws.Request ) {
551
- in := req .Params .(* testPageInput )
552
- if e , a := expect [i ].PrevToken , in .NextToken ; e != a {
553
- t .Errorf ("%d, expect NextToken input %q, got %q" , i , e , a )
554
- }
555
- })
556
- r .Handlers .Unmarshal .PushBack (func (req * aws.Request ) {
557
- out := & testPageOutput {
558
- Value : expect [i ].Value ,
559
- }
560
- if len (expect [i ].NextToken ) > 0 {
561
- out .NextToken = aws .String (expect [i ].NextToken )
562
- }
563
- req .Data = out
564
- })
565
- return r , nil
526
+ cases := map [string ][]testCase {
527
+ "nil NextToken" : {
528
+ testCase {aws .String ("FirstValue" ), aws .String ("InitalToken" ), aws .String ("FirstToken" )},
529
+ testCase {aws .String ("SecondValue" ), aws .String ("FirstToken" ), aws .String ("SecondToken" )},
530
+ testCase {aws .String ("ThirdValue" ), aws .String ("SecondToken" ), nil },
531
+ },
532
+ "zero NextToken" : {
533
+ testCase {aws .String ("FirstValue" ), aws .String ("InitalToken" ), aws .String ("FirstToken" )},
534
+ testCase {aws .String ("SecondValue" ), aws .String ("FirstToken" ), aws .String ("SecondToken" )},
535
+ testCase {aws .String ("ThirdValue" ), aws .String ("SecondToken" ), aws .String ("" )},
566
536
},
567
537
}
568
538
569
- for p .Next () {
570
- data := p .Page ().(* testPageOutput )
539
+ for cName , c := range cases {
540
+ t .Run (cName , func (t * testing.T ) {
541
+ input := testPageInput {
542
+ NextToken : c [0 ].PrevToken ,
543
+ }
571
544
572
- if e , a := expect [i ].Value , data .Value ; e != a {
573
- t .Errorf ("%d, expect Value to be %q, got %q" , i , e , a )
574
- }
575
- if e , a := expect [i ].NextToken , aws .StringValue (data .NextToken ); e != a {
576
- t .Errorf ("%d, expect NextToken to be %q, got %q" , i , e , a )
577
- }
545
+ svc := awstesting .NewClient (unit .Config ())
546
+ i := 0
547
+ p := aws.Pagination {
548
+ NewRequest : func () (* aws.Request , error ) {
549
+ r := svc .NewRequest (
550
+ & aws.Operation {
551
+ Name : "Operation" ,
552
+ Paginator : & aws.Paginator {
553
+ InputTokens : []string {"NextToken" },
554
+ OutputTokens : []string {"NextToken" },
555
+ },
556
+ },
557
+ & input , & testPageOutput {},
558
+ )
559
+ // Setup handlers for testing
560
+ r .Handlers .Clear ()
561
+ r .Handlers .Build .PushBack (func (req * aws.Request ) {
562
+ if e , a := len (c ), i + 1 ; a > e {
563
+ t .Fatalf ("expect no more than %d requests, got %d" , e , a )
564
+ }
565
+ in := req .Params .(* testPageInput )
566
+ if e , a := aws .StringValue (c [i ].PrevToken ), aws .StringValue (in .NextToken ); e != a {
567
+ t .Errorf ("%d, expect NextToken input %q, got %q" , i , e , a )
568
+ }
569
+ })
570
+ r .Handlers .Unmarshal .PushBack (func (req * aws.Request ) {
571
+ out := & testPageOutput {
572
+ Value : c [i ].Value ,
573
+ }
574
+ if c [i ].NextToken != nil {
575
+ next := * c [i ].NextToken
576
+ out .NextToken = aws .String (next )
577
+ }
578
+ req .Data = out
579
+ })
580
+ return r , nil
581
+ },
582
+ }
578
583
579
- i ++
580
- }
581
- if e , a := len (expect ), i ; e != a {
582
- t .Errorf ("expected to process %d pages, did %d" , e , a )
583
- }
584
- if err := p .Err (); err != nil {
585
- t .Fatalf ("%d, expected no error, got %v" , i , err )
586
- }
587
- }
584
+ for p .Next () {
585
+ data := p .Page ().(* testPageOutput )
588
586
589
- func TestPagination_Standalone_Pointers (t * testing.T ) {
590
- type testPageInput struct {
591
- NextToken * string
592
- }
593
- type testPageOutput struct {
594
- Value * string
595
- NextToken * string
596
- }
597
-
598
- expect := []struct {
599
- Value , PrevToken , NextToken * string
600
- }{
601
- {aws .String ("FirstValue" ), aws .String ("InitalToken" ), aws .String ("FirstToken" )},
602
- {aws .String ("SecondValue" ), aws .String ("FirstToken" ), aws .String ("SecondToken" )},
603
- {aws .String ("ThirdValue" ), aws .String ("SecondToken" ), nil },
604
- }
605
- input := testPageInput {
606
- NextToken : expect [0 ].PrevToken ,
607
- }
608
-
609
- c := awstesting .NewClient (unit .Config ())
610
- i := 0
611
- p := aws.Pagination {
612
- NewRequest : func () (* aws.Request , error ) {
613
- r := c .NewRequest (
614
- & aws.Operation {
615
- Name : "Operation" ,
616
- Paginator : & aws.Paginator {
617
- InputTokens : []string {"NextToken" },
618
- OutputTokens : []string {"NextToken" },
619
- },
620
- },
621
- & input , & testPageOutput {},
622
- )
623
- // Setup handlers for testing
624
- r .Handlers .Clear ()
625
- r .Handlers .Build .PushBack (func (req * aws.Request ) {
626
- in := req .Params .(* testPageInput )
627
- if e , a := aws .StringValue (expect [i ].PrevToken ), aws .StringValue (in .NextToken ); e != a {
628
- t .Errorf ("%d, expect NextToken input %q, got %q" , i , e , a )
629
- }
630
- })
631
- r .Handlers .Unmarshal .PushBack (func (req * aws.Request ) {
632
- out := & testPageOutput {
633
- Value : expect [i ].Value ,
587
+ if e , a := aws .StringValue (c [i ].Value ), aws .StringValue (data .Value ); e != a {
588
+ t .Errorf ("%d, expect Value to be %q, got %q" , i , e , a )
634
589
}
635
- if expect [i ].NextToken != nil {
636
- next := * expect [i ].NextToken
637
- out .NextToken = aws .String (next )
590
+ if e , a := aws .StringValue (c [i ].NextToken ), aws .StringValue (data .NextToken ); e != a {
591
+ t .Errorf ("%d, expect NextToken to be %q, got %q" , i , e , a )
638
592
}
639
- req .Data = out
640
- })
641
- return r , nil
642
- },
643
- }
644
593
645
- for p .Next () {
646
- data := p .Page ().(* testPageOutput )
647
-
648
- if e , a := expect [i ].Value , data .Value ; e != a {
649
- t .Errorf ("%d, expect Value to be %q, got %q" , i , e , a )
650
- }
651
- if e , a := aws .StringValue (expect [i ].NextToken ), aws .StringValue (data .NextToken ); e != a {
652
- t .Errorf ("%d, expect NextToken to be %q, got %q" , i , e , a )
653
- }
654
-
655
- i ++
656
- }
657
- if e , a := len (expect ), i ; e != a {
658
- t .Errorf ("expected to process %d pages, did %d" , e , a )
659
- }
660
- if err := p .Err (); err != nil {
661
- t .Fatalf ("%d, expected no error, got %v" , i , err )
594
+ i ++
595
+ }
596
+ if e , a := len (c ), i ; e != a {
597
+ t .Errorf ("expected to process %d pages, did %d" , e , a )
598
+ }
599
+ if err := p .Err (); err != nil {
600
+ t .Fatalf ("%d, expected no error, got %v" , i , err )
601
+ }
602
+ })
662
603
}
663
604
}
664
605
0 commit comments