Skip to content

Commit

Permalink
Don't skip URLs for remotes table
Browse files Browse the repository at this point in the history
Signed-off-by: kuba-- <[email protected]>
  • Loading branch information
kuba-- committed Apr 9, 2019
1 parent 6293321 commit 145a26a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 24 deletions.
37 changes: 36 additions & 1 deletion common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"gopkg.in/src-d/go-billy-siva.v4"
sivafs "gopkg.in/src-d/go-billy-siva.v4"
billy "gopkg.in/src-d/go-billy.v4"
"gopkg.in/src-d/go-billy.v4/osfs"
fixtures "gopkg.in/src-d/go-git-fixtures.v3"
Expand Down Expand Up @@ -243,6 +243,41 @@ func testTableIndexIterClosed(t *testing.T, table sql.IndexableTable) {
require.True(closed.Check())
}

func testTableIterators(t *testing.T, table sql.IndexableTable, columns []string) {
t.Helper()

require := require.New(t)
ctx, closed := setupSivaCloseRepos(t, "_testdata")

rows, _ := tableToRows(ctx, table)
expected := len(rows)

iter, err := table.IndexKeyValues(ctx, columns)
require.NoError(err)
actual := 0
for {
_, i, err := iter.Next()
if err != nil {
require.Equal(io.EOF, err)
break
}
for {
_, _, err := i.Next()
if err != nil {
require.Equal(io.EOF, err)
break
}
actual++
}

i.Close()
}
iter.Close()
require.True(closed.Check())

require.EqualValues(expected, actual)
}

func testTableIterClosed(t *testing.T, table sql.IndexableTable) {
t.Helper()

Expand Down
50 changes: 29 additions & 21 deletions remotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,28 +144,25 @@ type remotesRowIter struct {
}

func (i *remotesRowIter) Next() (sql.Row, error) {
if i.remotePos >= len(i.remotes) {
return nil, io.EOF
}

remote := i.remotes[i.remotePos]
config := remote.Config()

if i.urlPos >= len(config.URLs) || i.urlPos >= len(config.Fetch) {
i.remotePos++
for {
if i.remotePos >= len(i.remotes) {
return nil, io.EOF
}

remote = i.remotes[i.remotePos]
config = remote.Config()
i.urlPos = 0
}
remote := i.remotes[i.remotePos]
config := remote.Config()

if i.urlPos >= len(config.URLs) && i.urlPos >= len(config.Fetch) {
i.remotePos++
i.urlPos = 0
continue
}

row := remoteToRow(i.repo.ID, config, i.urlPos)
i.urlPos++
row := remoteToRow(i.repo.ID, config, i.urlPos)
i.urlPos++

return row, nil
return row, nil
}
}

func (i *remotesRowIter) Close() error {
Expand All @@ -177,13 +174,23 @@ func (i *remotesRowIter) Close() error {
}

func remoteToRow(repoID string, config *config.RemoteConfig, pos int) sql.Row {
url := ""
if pos < len(config.URLs) {
url = config.URLs[pos]
}

fetch := ""
if pos < len(config.Fetch) {
fetch = config.Fetch[pos].String()
}

return sql.NewRow(
repoID,
config.Name,
config.URLs[pos],
config.URLs[pos],
config.Fetch[pos].String(),
config.Fetch[pos].String(),
url,
url,
fetch,
fetch,
)
}

Expand Down Expand Up @@ -256,7 +263,8 @@ func (i *remotesKeyValueIter) Next() ([]interface{}, []byte, error) {
}

cfg := i.remotes[i.pos].Config()
if i.urlPos >= len(cfg.URLs) {
if i.urlPos >= len(cfg.URLs) && i.urlPos >= len(cfg.Fetch) {
i.urlPos = 0
i.pos++
continue
}
Expand Down
5 changes: 3 additions & 2 deletions remotes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func TestRemotesIndexIterClosed(t *testing.T) {
testTableIndexIterClosed(t, new(remotesTable))
}

func TestRemotesIterClosed(t *testing.T) {
testTableIterClosed(t, new(remotesTable))
func TestRemotesIterators(t *testing.T) {
// columns names just for debugging
testTableIterators(t, new(remotesTable), []string{"remote_name", "remote_push_url"})
}

0 comments on commit 145a26a

Please sign in to comment.