Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tag list in gcs backend #197

Merged
merged 5 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions lib/backend/gcsbackend/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,28 @@ func (c *Client) List(prefix string, opts ...backend.ListOption) (*backend.ListR
}

pager := iterator.NewPager(pageIterator, maxKeys, paginationToken)
result, err := c.gcs.NextPage(pager)
blobs, continuationToken, err := c.gcs.NextPage(pager)
if err != nil {
return nil, err
}

var names []string
for _, b := range blobs {
name, err := c.pather.NameFromBlobPath(b)
if err != nil {
log.With("blob", b).Errorf("Error converting blob path into name: %s", err)
continue
}
names = append(names, name)
}
result := &backend.ListResult{
Names: names,
ContinuationToken: continuationToken,
}

if !options.Paginated {
result.ContinuationToken = ""
}

return result, nil
}

Expand Down Expand Up @@ -261,21 +275,18 @@ func (g *GCSImpl) GetObjectIterator(prefix string) iterator.Pageable {
return g.bucket.Objects(g.ctx, &query)
}

func (g *GCSImpl) NextPage(pager *iterator.Pager) (*backend.ListResult,
func (g *GCSImpl) NextPage(pager *iterator.Pager) ([]string, string,
error) {

var objectAttrs []*storage.ObjectAttrs
continuationToken, err := pager.NextPage(&objectAttrs)
if err != nil {
return nil, err
return nil, "", err
}

names := make([]string, len(objectAttrs))
for idx, objectAttr := range objectAttrs {
names[idx] = objectAttr.Name
}
return &backend.ListResult{
Names: names,
ContinuationToken: continuationToken,
}, nil
return names, continuationToken, nil
}
8 changes: 3 additions & 5 deletions lib/backend/gcsbackend/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,19 @@ func TestClientList(t *testing.T) {
for i := 0; i < maxIterate; {
count := (rand.Int() % 10) + 1
var expected []string
var ret []string
for j := i; j < (i+count) && j < maxIterate; j++ {
expected = append(expected, "test/"+strconv.Itoa(j))
ret = append(ret, "/root/test/"+strconv.Itoa(j))
}

continuationToken := ""
if (i + count) < maxIterate {
strconv.Itoa(i + count)
}
result := &backend.ListResult{
Names: expected,
ContinuationToken: continuationToken,
}
mocks.gcs.EXPECT().NextPage(
gomock.Any(),
).Return(result, nil)
).Return(ret, continuationToken, nil)

result, err := client.List("test", backend.ListWithPagination(),
backend.ListWithMaxKeys(count),
Expand Down
3 changes: 1 addition & 2 deletions lib/backend/gcsbackend/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"io"

"cloud.google.com/go/storage"
"github.com/uber/kraken/lib/backend"
"google.golang.org/api/iterator"
)

Expand All @@ -27,5 +26,5 @@ type GCS interface {
Download(objectName string, w io.Writer) (int64, error)
Upload(objectName string, r io.Reader) (int64, error)
GetObjectIterator(prefix string) iterator.Pageable
NextPage(pager *iterator.Pager) (*backend.ListResult, error)
NextPage(pager *iterator.Pager) ([]string, string, error)
}
10 changes: 5 additions & 5 deletions mocks/lib/backend/gcsbackend/gcs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.