Skip to content

Commit 3589daf

Browse files
committed
Add test for NewIterator error in rowReader
Signed-off-by: Javi Fontan <[email protected]>
1 parent 2e95291 commit 3589daf

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

repository_pool_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ package gitbase
22

33
import (
44
"context"
5+
"fmt"
56
"io"
67
"io/ioutil"
78
"os"
89
"path/filepath"
910
"strconv"
1011
"sync"
1112
"testing"
13+
"time"
1214

1315
"github.com/stretchr/testify/require"
1416
"gopkg.in/src-d/go-git-fixtures.v3"
@@ -263,3 +265,49 @@ func TestRepositoryPoolAddDir(t *testing.T) {
263265

264266
require.ElementsMatch(arrayExpected, arrayID)
265267
}
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

Comments
 (0)