mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-12 16:47:41 +02:00
databroker: add support for querying the databroker (#1443)
* databroker: add support for querying the databroker * remove query method, use getall so encryption works * add test * return early
This commit is contained in:
parent
fdec45fe04
commit
2364da14c8
8 changed files with 534 additions and 118 deletions
46
pkg/grpc/databroker/databroker_test.go
Normal file
46
pkg/grpc/databroker/databroker_test.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package databroker
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestApplyOffsetAndLimit(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
records []*Record
|
||||
offset, limit int
|
||||
expect []*Record
|
||||
}{
|
||||
{
|
||||
name: "empty",
|
||||
records: nil,
|
||||
offset: 10,
|
||||
limit: 5,
|
||||
expect: nil,
|
||||
},
|
||||
{
|
||||
name: "less than limit",
|
||||
records: []*Record{{Id: "A"}, {Id: "B"}, {Id: "C"}, {Id: "D"}},
|
||||
offset: 1,
|
||||
limit: 10,
|
||||
expect: []*Record{{Id: "B"}, {Id: "C"}, {Id: "D"}},
|
||||
},
|
||||
{
|
||||
name: "more than limit",
|
||||
records: []*Record{{Id: "A"}, {Id: "B"}, {Id: "C"}, {Id: "D"}, {Id: "E"}, {Id: "F"}, {Id: "G"}, {Id: "H"}},
|
||||
offset: 3,
|
||||
limit: 2,
|
||||
expect: []*Record{{Id: "D"}, {Id: "E"}},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
actual, cnt := ApplyOffsetAndLimit(tc.records, tc.offset, tc.limit)
|
||||
assert.Equal(t, len(tc.records), cnt)
|
||||
assert.Equal(t, tc.expect, actual)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue