@@ -2,6 +2,7 @@ package gitbase
22
33import (
44 "io"
5+ "strconv"
56 "testing"
67
78 "github.com/src-d/go-mysql-server/sql"
@@ -146,3 +147,60 @@ func TestPartitionRowsWithIndex(t *testing.T) {
146147
147148 require .ElementsMatch (expected , result )
148149}
150+
151+ func TestCommitFilesIndexIter (t * testing.T ) {
152+ require := require .New (t )
153+
154+ ctx , _ , cleanup := setupRepos (t )
155+ defer cleanup ()
156+
157+ key := & commitFileIndexKey {
158+ Repository : "zero" ,
159+ Packfile : plumbing .ZeroHash .String (),
160+ Hash : plumbing .ZeroHash .String (),
161+ Offset : 0 ,
162+ Name : "two" ,
163+ Mode : 5 ,
164+ Tree : plumbing .ZeroHash .String (),
165+ Commit : plumbing .ZeroHash .String (),
166+ }
167+ limit := 10
168+ it := newCommitFilesIndexIter (testIndexValueIter {key , int64 (limit )}, poolFromCtx (t , ctx ))
169+ for off := 0 ; off < limit ; off ++ {
170+ row , err := it .Next ()
171+ require .NoError (err )
172+
173+ require .Equal (key .Repository , row [0 ])
174+ require .Equal (strconv .Itoa (off ), row [2 ])
175+ }
176+ _ , err := it .Next ()
177+ require .EqualError (err , io .EOF .Error ())
178+ }
179+
180+ type testIndexValueIter struct {
181+ key * commitFileIndexKey
182+ limit int64
183+ }
184+
185+ func (it testIndexValueIter ) Next () ([]byte , error ) {
186+ if it .key .Offset >= it .limit {
187+ return nil , io .EOF
188+ }
189+
190+ it .key .Name = strconv .Itoa (int (it .key .Offset ))
191+ val , err := it .key .encode ()
192+ if err != nil {
193+ return nil , err
194+ }
195+ val , err = encoder .encode (val )
196+ if err != nil {
197+ return nil , err
198+ }
199+
200+ it .key .Offset ++
201+ return val , nil
202+ }
203+
204+ func (it testIndexValueIter ) Close () error {
205+ return nil
206+ }
0 commit comments