pomerium/pkg/grpc/databroker/databroker_test.go
Caleb Doxsey 2364da14c8
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
2020-09-22 16:01:37 -06:00

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)
})
}
}