Skip to content
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

Add filter to next page token so it applies to subsequently requested pages #1153

Merged
merged 2 commits into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add filter to next page token so it applies to subsequently requested…
… pages.
  • Loading branch information
neuromage committed Apr 12, 2019
commit 58afe895465e89a40c4d63638b1797e2b4352b1b
1 change: 1 addition & 0 deletions backend/src/apiserver/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ func (o *Options) nextPageToken(listable Listable) (*token, error) {
KeyFieldName: listable.PrimaryKeyColumnName(),
KeyFieldValue: keyField.Interface(),
IsDesc: o.IsDesc,
Filter: o.Filter,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we verify the token can be correctly marshalled into expected string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch @IronPan ! This was completely missing from before. Best part is, we had a test that would have caught it in experiment_store_test.go, but somehow, it too was testing the wrong value! Fixed this and added tests for serialization/deserialization of token and filter. PTAL.

}, nil
}

Expand Down
30 changes: 29 additions & 1 deletion backend/src/apiserver/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ func (f *fakeListable) APIToModelFieldMap() map[string]string {
func TestNextPageToken_ValidTokens(t *testing.T) {
l := &fakeListable{PrimaryKey: "uuid123", FakeName: "Fake", CreatedTimestamp: 1234}

protoFilter := &api.Filter{Predicates: []*api.Predicate{
&api.Predicate{
Key: "name",
Op: api.Predicate_EQUALS,
Value: &api.Predicate_StringValue{StringValue: "SomeName"},
}}}
testFilter, err := filter.New(protoFilter)
if err != nil {
t.Fatalf("failed to parse filter proto %+v: %v", protoFilter, err)
}

tests := []struct {
inOpts *Options
want *token
Expand Down Expand Up @@ -82,12 +93,29 @@ func TestNextPageToken_ValidTokens(t *testing.T) {
IsDesc: false,
},
},
{
inOpts: &Options{
PageSize: 10,
token: &token{
SortByFieldName: "FakeName", IsDesc: false,
Filter: testFilter,
},
},
want: &token{
SortByFieldName: "FakeName",
SortByFieldValue: "Fake",
KeyFieldName: "PrimaryKey",
KeyFieldValue: "uuid123",
IsDesc: false,
Filter: testFilter,
},
},
}

for _, test := range tests {
got, err := test.inOpts.nextPageToken(l)

if !cmp.Equal(got, test.want) || err != nil {
if !cmp.Equal(got, test.want, cmp.AllowUnexported(filter.Filter{})) || err != nil {
t.Errorf("nextPageToken(%+v, %+v) =\nGot: %+v, %+v\nWant: %+v, <nil>\nDiff:\n%s",
test.inOpts, l, got, err, test.want, cmp.Diff(test.want, got))
}
Expand Down