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 3b9040a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
11 changes: 10 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/monzo/gocassa

go 1.15
go 1.21

require (
github.com/gocql/gocql v0.0.0-20201024154641-5913df4d474e
Expand All @@ -9,3 +9,12 @@ require (
github.com/mattheath/kala v0.0.0-20171219141654-d6276794bf0e
github.com/stretchr/testify v1.6.1
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/golang/snappy v0.0.0-20170215233205-553a64147049 // indirect
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY=
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -10,8 +12,10 @@ github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattheath/base62 v0.0.0-20150408093626-b80cdc656a7a h1:rnrxZue85aKdMU4nJ50GgKA31lCaVbft+7Xl8OXj55U=
github.com/mattheath/base62 v0.0.0-20150408093626-b80cdc656a7a/go.mod h1:hJJYoBMTZIONmUEpX3+9v2057zuRM0n3n77U4Ob4wE4=
Expand All @@ -23,6 +27,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
Expand Down
7 changes: 7 additions & 0 deletions mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"reflect"
"slices"

Check failure on line 8 in mock.go

View workflow job for this annotation

GitHub Actions / test (1.18.x, ubuntu-latest)

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.18.10/x64/src/slices)

Check failure on line 8 in mock.go

View workflow job for this annotation

GitHub Actions / test (1.19.x, ubuntu-latest)

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.19.13/x64/src/slices)
"strings"
"sync"

Expand Down Expand Up @@ -626,6 +627,12 @@ func (q *MockFilter) Read(out interface{}) Op {
}

opt := q.table.options.Merge(m.options)

// If a query-level clustering order has been provided, and the first one is descending, reverse the list
if len(opt.ClusteringOrder) > 0 && opt.ClusteringOrder[0].Direction == DESC {
slices.Reverse(result)
}

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 3b9040a

Please # to comment.