From 2ae7fb2fa80a071f75b93dbf37f6fac8d737fab4 Mon Sep 17 00:00:00 2001 From: nadavsteindler Date: Mon, 16 Dec 2024 11:41:56 +0200 Subject: [PATCH] moar tests --- cmd/lakefs/cmd/run.go | 2 +- pkg/api/controller.go | 2 +- pkg/catalog/catalog.go | 15 +++++++++++++-- pkg/catalog/catalog_test.go | 14 ++++++++++++++ pkg/gateway/operations/listbuckets.go | 2 +- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/cmd/lakefs/cmd/run.go b/cmd/lakefs/cmd/run.go index 9a3263adb2a..7e1e832f01a 100644 --- a/cmd/lakefs/cmd/run.go +++ b/cmd/lakefs/cmd/run.go @@ -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") } diff --git a/pkg/api/controller.go b/pkg/api/controller.go index 7004db34abe..d7e78eb38a6 100644 --- a/pkg/api/controller.go +++ b/pkg/api/controller.go @@ -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 } diff --git a/pkg/catalog/catalog.go b/pkg/catalog/catalog.go index 65c24de2b85..af7193e85e3 100644 --- a/pkg/catalog/catalog.go +++ b/pkg/catalog/catalog.go @@ -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 diff --git a/pkg/catalog/catalog_test.go b/pkg/catalog/catalog_test.go index 2304e68c55c..9880f80f6c5 100644 --- a/pkg/catalog/catalog_test.go +++ b/pkg/catalog/catalog_test.go @@ -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{ diff --git a/pkg/gateway/operations/listbuckets.go b/pkg/gateway/operations/listbuckets.go index 8fde6c8151c..8bd9e7a9099 100644 --- a/pkg/gateway/operations/listbuckets.go +++ b/pkg/gateway/operations/listbuckets.go @@ -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