Skip to content

Commit

Permalink
moar tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nadavsteindler committed Dec 16, 2024
1 parent ae8267f commit 2ae7fb2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/lakefs/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func checkRepos(ctx context.Context, logger logging.Logger, authMetadataManager
for hasMore {
var err error
var repos []*catalog.Repository
repos, hasMore, err = c.ListRepositories(ctx, -1, "", next)
repos, hasMore, err = c.ListRepositories(ctx, -1, "", "", next)
if err != nil {
logger.WithError(err).Fatal("Checking existing repositories failed")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,7 @@ func (c *Controller) ListRepositories(w http.ResponseWriter, r *http.Request, pa
ctx := r.Context()
c.LogAction(ctx, "list_repos", r, "", "", "")

repos, hasMore, err := c.Catalog.ListRepositories(ctx, paginationAmount(params.Amount), paginationPrefix(params.Prefix), paginationAfter(params.After))
repos, hasMore, err := c.Catalog.ListRepositories(ctx, paginationAmount(params.Amount), paginationPrefix(params.Prefix), "", paginationAfter(params.After))
if c.handleAPIError(ctx, w, r, err) {
return
}
Expand Down
15 changes: 13 additions & 2 deletions pkg/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,12 +598,23 @@ func (c *Catalog) ListRepositories(ctx context.Context, limit int, prefix, searc
defer it.Close()
// seek for first item
afterRepositoryID := graveler.RepositoryID(after)
if after != "" {
it.SeekGE(afterRepositoryID)
prefixRepositoryID := graveler.RepositoryID(prefix)
startPos := prefixRepositoryID
if afterRepositoryID > startPos {
startPos = afterRepositoryID
}
if startPos != "" {
it.SeekGE(startPos)
}

var repos []*Repository
for it.Next() {
record := it.Value()

if !strings.HasPrefix(string(record.RepositoryID), prefix) {
break
}

if strings.Contains(string(record.RepositoryID), searchString) {
if record.RepositoryID == afterRepositoryID {
continue
Expand Down
14 changes: 14 additions & 0 deletions pkg/catalog/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ func TestCatalog_ListRepositories(t *testing.T) {
wantHasMore: true,
wantErr: false,
},
{
name: "prefix",
args: args{
limit: 1,
after: "",
prefix: "repo",
searchString: "",
},
want: []*catalog.Repository{
{Name: "repo1", StorageNamespace: "storage2", DefaultBranch: "main2", CreationDate: now},
},
wantHasMore: true,
wantErr: false,
},
{
name: "last2",
args: args{
Expand Down
2 changes: 1 addition & 1 deletion pkg/gateway/operations/listbuckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (controller *ListBuckets) Handle(w http.ResponseWriter, req *http.Request,
var after string
for {
// list repositories
repos, hasMore, err := o.Catalog.ListRepositories(req.Context(), -1, "", after)
repos, hasMore, err := o.Catalog.ListRepositories(req.Context(), -1, "", "", after)
if err != nil {
_ = o.EncodeError(w, req, err, errors.Codes.ToAPIErr(errors.ErrInternalError))
return
Expand Down

0 comments on commit 2ae7fb2

Please sign in to comment.