package cache import ( "fmt" "testing" . "github.com/smartystreets/goconvey/convey" ) func Test_FindSegmentIndex(t *testing.T) { cases := []struct { title string buffer SegmentBuffer postions []int64 wants []int }{ { buffer: SegmentBuffer{ buzys: []*FileSegment{ {Position: 0}, {Position: 10}, }, }, postions: []int64{0, 2, 10, 11}, wants: []int{0, 0, 1, 1}, }, } for i, c := range cases { for j, _ := range c.postions { Convey(fmt.Sprintf("%d.%d. %s", i, j, c.title), t, func() { got := c.buffer.FirstContains(c.postions[j]) So(got, ShouldEqual, c.wants[j]) }) } } }