mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-30 02:46:30 +02:00
* databroker: add support for querying the databroker * remove query method, use getall so encryption works * add test * return early
46 lines
992 B
Go
46 lines
992 B
Go
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)
|
|
})
|
|
}
|
|
}
|