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:
Caleb Doxsey 2020-09-22 16:01:37 -06:00 committed by GitHub
parent fdec45fe04
commit 2364da14c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 534 additions and 118 deletions

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