Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavlo Strokov <pstrokov@gitlab.com>2022-01-20 22:18:41 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2022-02-23 11:47:18 +0300
commit3181a79fac67c1cb9e48312551ddc8e81ab66d42 (patch)
tree1a0363b2b5377edce0aed1806d02ec0ab82e0a97
parent090f5dbc5c6bd8a889b076f35ab9bfbfd8a426f8 (diff)
repository: Extend test coverage for MidxRepack RPC
If repository is not provided the RPC returns specific error about it. Make sure NotFound code and specific message is returned in case requested repository doesn't exist on the disk. It requires skip error wrapping in case SetConfig() returns status.Status.
-rw-r--r--internal/gitaly/service/repository/midx.go9
-rw-r--r--internal/gitaly/service/repository/midx_test.go36
2 files changed, 45 insertions, 0 deletions
diff --git a/internal/gitaly/service/repository/midx.go b/internal/gitaly/service/repository/midx.go
index 2dc429b70..0540e2ae1 100644
--- a/internal/gitaly/service/repository/midx.go
+++ b/internal/gitaly/service/repository/midx.go
@@ -9,12 +9,14 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
log "github.com/sirupsen/logrus"
+ gitalyerrors "gitlab.com/gitlab-org/gitaly/v14/internal/errors"
"gitlab.com/gitlab-org/gitaly/v14/internal/git"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/housekeeping"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/repository"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/stats"
"gitlab.com/gitlab-org/gitaly/v14/internal/helper"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
+ "google.golang.org/grpc/status"
)
const (
@@ -24,9 +26,16 @@ const (
func (s *server) MidxRepack(ctx context.Context, in *gitalypb.MidxRepackRequest) (*gitalypb.MidxRepackResponse, error) {
repoProto := in.GetRepository()
+ if repoProto == nil {
+ return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ }
+
repo := s.localrepo(repoProto)
if err := repo.SetConfig(ctx, "core.multiPackIndex", "true", s.txManager); err != nil {
+ if _, ok := status.FromError(err); ok {
+ return nil, err
+ }
return nil, helper.ErrInternalf("setting config: %w", err)
}
diff --git a/internal/gitaly/service/repository/midx_test.go b/internal/gitaly/service/repository/midx_test.go
index 5abd2fc2f..984f4ee44 100644
--- a/internal/gitaly/service/repository/midx_test.go
+++ b/internal/gitaly/service/repository/midx_test.go
@@ -21,7 +21,9 @@ import (
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testserver"
"gitlab.com/gitlab-org/gitaly/v14/internal/transaction/txinfo"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
+ "google.golang.org/grpc/codes"
"google.golang.org/grpc/peer"
+ "google.golang.org/grpc/status"
)
func TestMidxWrite(t *testing.T) {
@@ -270,3 +272,37 @@ func addPackFiles(
}
}
}
+
+func TestMidxRepack_validationChecks(t *testing.T) {
+ t.Parallel()
+ cfg, client := setupRepositoryServiceWithoutRepo(t, testserver.WithDisablePraefect())
+ ctx := testhelper.Context(t)
+
+ for _, tc := range []struct {
+ desc string
+ req *gitalypb.MidxRepackRequest
+ expErr error
+ }{
+ {
+ desc: "no repository",
+ req: &gitalypb.MidxRepackRequest{},
+ expErr: status.Error(codes.InvalidArgument, "empty Repository"),
+ },
+ {
+ desc: "invalid storage",
+ req: &gitalypb.MidxRepackRequest{Repository: &gitalypb.Repository{StorageName: "invalid"}},
+ expErr: status.Error(codes.InvalidArgument, `GetStorageByName: no such storage: "invalid"`),
+ },
+ {
+ desc: "not existing repository",
+ req: &gitalypb.MidxRepackRequest{Repository: &gitalypb.Repository{StorageName: cfg.Storages[0].Name, RelativePath: "invalid"}},
+ expErr: status.Error(codes.NotFound, fmt.Sprintf(`GetRepoPath: not a git repository: "%s/invalid"`, cfg.Storages[0].Path)),
+ },
+ } {
+ t.Run(tc.desc, func(t *testing.T) {
+ //nolint:staticcheck
+ _, err := client.MidxRepack(ctx, tc.req)
+ testhelper.RequireGrpcError(t, tc.expErr, err)
+ })
+ }
+}