Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Add support for query-level DESC clustering order in the mock
Browse files Browse the repository at this point in the history
  • Loading branch information
gcjensen committed Jan 15, 2024
1 parent c4bedde commit a5e658c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,13 @@ func (q *MockFilter) Read(out interface{}) Op {
return err
}

// If a query-level clustering order has been provided, and the first one is descending, reverse the list
if len(m.options.ClusteringOrder) > 0 && m.options.ClusteringOrder[0].Direction == DESC {
for i, j := 0, len(result)-1; i < j; i, j = i+1, j-1 {
result[i], result[j] = result[j], result[i]
}
}

opt := q.table.options.Merge(m.options)
if opt.Limit > 0 && opt.Limit < len(result) {
result = result[:opt.Limit]
Expand Down
8 changes: 8 additions & 0 deletions mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,14 @@ func (s *MockSuite) TestMultiMapTableList() {
s.NoError(s.mmapTbl.List(1, 2, 1, &users).Run())
s.Len(users, 1)
s.Equal("Joe", users[0].Name)

// Order DESC
s.NoError(s.mmapTbl.List(1, 0, 10, &users).WithOptions(Options{
ClusteringOrder: []ClusteringOrderColumn{{Column: "Name", Direction: DESC}},
}).Run())
s.Len(users, 2)
s.Equal("Joe", users[0].Name)
s.Equal("Jane", users[1].Name)
}

func (s *MockSuite) TestMultiMapTableUpdate() {
Expand Down

0 comments on commit a5e658c

Please # to comment.