@@ -2,13 +2,15 @@ package gitbase
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
"io"
6
7
"io/ioutil"
7
8
"os"
8
9
"path/filepath"
9
10
"strconv"
10
11
"sync"
11
12
"testing"
13
+ "time"
12
14
13
15
"github.com/stretchr/testify/require"
14
16
"gopkg.in/src-d/go-git-fixtures.v3"
@@ -263,3 +265,49 @@ func TestRepositoryPoolAddDir(t *testing.T) {
263
265
264
266
require .ElementsMatch (arrayExpected , arrayID )
265
267
}
268
+
269
+ var errIter = fmt .Errorf ("Error iter" )
270
+
271
+ type testErrorIter struct {}
272
+
273
+ func (d * testErrorIter ) NewIterator (
274
+ repo * Repository ,
275
+ ) (RowRepoIter , error ) {
276
+ return nil , errIter
277
+ // return &testErrorIter{}, nil
278
+ }
279
+
280
+ func (d * testErrorIter ) Next () (sql.Row , error ) {
281
+ return nil , io .EOF
282
+ }
283
+
284
+ func (d * testErrorIter ) Close () error {
285
+ return nil
286
+ }
287
+
288
+ func TestRepositoryErrorIter (t * testing.T ) {
289
+ require := require .New (t )
290
+
291
+ path := fixtures .Basic ().ByTag ("worktree" ).One ().Worktree ().Root ()
292
+ pool := NewRepositoryPool ()
293
+ pool .Add ("one" , path )
294
+
295
+ timeout , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
296
+
297
+ ctx := sql .NewContext (timeout , sql .WithSession (NewSession (& pool )))
298
+ eIter := & testErrorIter {}
299
+
300
+ repoIter , err := NewRowRepoIter (ctx , eIter )
301
+ require .NoError (err )
302
+
303
+ go func () {
304
+ repoIter .Next ()
305
+ }()
306
+
307
+ select {
308
+ case <- repoIter .done :
309
+ require .Equal (errIter , repoIter .err )
310
+ }
311
+
312
+ cancel ()
313
+ }
0 commit comments