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