-
Notifications
You must be signed in to change notification settings - Fork 744
aws: Fix Pagination handling of empty string NextToken #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -511,15 +511,15 @@ func TestPaginationWithContextNilInput(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| type testPageInput struct { | ||
| NextToken string | ||
| } | ||
| type testPageOutput struct { | ||
| Value string | ||
| NextToken *string | ||
| } | ||
|
|
||
| func TestPagination_Standalone(t *testing.T) { | ||
| type testPageInput struct { | ||
| NextToken string | ||
| } | ||
| type testPageOutput struct { | ||
| Value string | ||
| NextToken *string | ||
| } | ||
|
|
||
| expect := []struct { | ||
| Value, PrevToken, NextToken string | ||
| }{ | ||
|
|
@@ -586,6 +586,82 @@ func TestPagination_Standalone(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestPagination_Standalone_Pointers(t *testing.T) { | ||
| type testPageInput struct { | ||
| NextToken *string | ||
| } | ||
| type testPageOutput struct { | ||
| Value *string | ||
| NextToken *string | ||
| } | ||
|
|
||
| expect := []struct { | ||
| Value, PrevToken, NextToken *string | ||
| }{ | ||
| {aws.String("FirstValue"), aws.String("InitalToken"), aws.String("FirstToken")}, | ||
| {aws.String("SecondValue"), aws.String("FirstToken"), aws.String("SecondToken")}, | ||
| {aws.String("ThirdValue"), aws.String("SecondToken"), nil}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we not have a test to test for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, TestPagination_Standalone is that testcase. The SDK already had this testcase but the way it worked prevented the bug from manifesting. |
||
| } | ||
| input := testPageInput{ | ||
| NextToken: expect[0].PrevToken, | ||
| } | ||
|
|
||
| c := awstesting.NewClient(unit.Config()) | ||
| i := 0 | ||
| p := aws.Pagination{ | ||
| NewRequest: func() (*aws.Request, error) { | ||
| r := c.NewRequest( | ||
| &aws.Operation{ | ||
| Name: "Operation", | ||
| Paginator: &aws.Paginator{ | ||
| InputTokens: []string{"NextToken"}, | ||
| OutputTokens: []string{"NextToken"}, | ||
| }, | ||
| }, | ||
| &input, &testPageOutput{}, | ||
| ) | ||
| // Setup handlers for testing | ||
| r.Handlers.Clear() | ||
| r.Handlers.Build.PushBack(func(req *aws.Request) { | ||
| in := req.Params.(*testPageInput) | ||
| if e, a := aws.StringValue(expect[i].PrevToken), aws.StringValue(in.NextToken); e != a { | ||
| t.Errorf("%d, expect NextToken input %q, got %q", i, e, a) | ||
| } | ||
| }) | ||
| r.Handlers.Unmarshal.PushBack(func(req *aws.Request) { | ||
| out := &testPageOutput{ | ||
| Value: expect[i].Value, | ||
| } | ||
| if expect[i].NextToken != nil { | ||
| next := *expect[i].NextToken | ||
| out.NextToken = aws.String(next) | ||
| } | ||
| req.Data = out | ||
| }) | ||
| return r, nil | ||
| }, | ||
| } | ||
|
|
||
| for p.Next() { | ||
| data := p.Page().(*testPageOutput) | ||
|
|
||
| if e, a := expect[i].Value, data.Value; e != a { | ||
| t.Errorf("%d, expect Value to be %q, got %q", i, e, a) | ||
| } | ||
| if e, a := aws.StringValue(expect[i].NextToken), aws.StringValue(data.NextToken); e != a { | ||
| t.Errorf("%d, expect NextToken to be %q, got %q", i, e, a) | ||
| } | ||
|
|
||
| i++ | ||
| } | ||
| if e, a := len(expect), i; e != a { | ||
| t.Errorf("expected to process %d pages, did %d", e, a) | ||
| } | ||
| if err := p.Err(); err != nil { | ||
| t.Fatalf("%d, expected no error, got %v", i, err) | ||
| } | ||
| } | ||
|
|
||
| // Benchmarks | ||
| var benchResps = []dynamodb.ListTablesOutput{ | ||
| {TableNames: []string{"TABLE", "NXT"}, LastEvaluatedTableName: aws.String("NXT")}, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if they are bunch of empy strings, wouldn't
tokenAddednot be set totrue? Meaning this would never return thetokensThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tokenAddedis present if a valid token is added. Thetokensslice is a sparse array. Its index directly correspond to indexes in another slice.If all of the values at the
outTokenspaths are empty strings there will be no valid tokens in thetokensslice. In that case returningnilwould be the correct action. If there is at least one valid value inoutTokenspaths thetokenAddedwill be set to true.