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 19:34:58 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2022-02-23 11:47:18 +0300
commita7ee0e1e10e0532852082e8788528888bb3923b3 (patch)
tree0ed20225c35e9e2ba5a4c790bdf8209205d67a58
parent9cd4fb1073d55858b23562f947dd0565a6685f30 (diff)
repository: Extend test coverage for RenameRepository RPC
Make sure NotFound code and specific message is returned in case requested repository doesn't exist on the disk.
-rw-r--r--internal/gitaly/service/repository/rename.go3
-rw-r--r--internal/gitaly/service/repository/rename_test.go22
-rw-r--r--internal/gitaly/service/repository/testhelper_test.go7
3 files changed, 29 insertions, 3 deletions
diff --git a/internal/gitaly/service/repository/rename.go b/internal/gitaly/service/repository/rename.go
index b161b4a9e..9f619e4e2 100644
--- a/internal/gitaly/service/repository/rename.go
+++ b/internal/gitaly/service/repository/rename.go
@@ -8,6 +8,7 @@ import (
"path/filepath"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
+ gitalyerrors "gitlab.com/gitlab-org/gitaly/v14/internal/errors"
"gitlab.com/gitlab-org/gitaly/v14/internal/helper"
"gitlab.com/gitlab-org/gitaly/v14/internal/safe"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
@@ -97,7 +98,7 @@ func (s *server) renameRepository(ctx context.Context, sourceRepo, targetRepo *g
func validateRenameRepositoryRequest(in *gitalypb.RenameRepositoryRequest) error {
if in.GetRepository() == nil {
- return errors.New("from repository is empty")
+ return gitalyerrors.ErrEmptyRepository
}
if in.GetRelativePath() == "" {
diff --git a/internal/gitaly/service/repository/rename_test.go b/internal/gitaly/service/repository/rename_test.go
index c3528cf1d..16ab49e43 100644
--- a/internal/gitaly/service/repository/rename_test.go
+++ b/internal/gitaly/service/repository/rename_test.go
@@ -1,8 +1,10 @@
package repository
import (
+ "fmt"
"os"
"path/filepath"
+ "strings"
"testing"
"github.com/stretchr/testify/require"
@@ -13,6 +15,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testserver"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"google.golang.org/grpc/codes"
+ "google.golang.org/grpc/status"
)
func TestRenameRepository_success(t *testing.T) {
@@ -73,30 +76,45 @@ func TestRenameRepository_invalidRequest(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- _, repo, _, client := setupRepositoryService(ctx, t)
+ _, repo, repoPath, client := setupRepositoryService(ctx, t)
+ storagePath := strings.TrimSuffix(repoPath, "/"+repo.RelativePath)
testCases := []struct {
desc string
req *gitalypb.RenameRepositoryRequest
+ exp error
}{
{
desc: "empty repository",
req: &gitalypb.RenameRepositoryRequest{Repository: nil, RelativePath: "/tmp/abc"},
+ exp: status.Error(codes.InvalidArgument, gitalyOrPraefect("empty Repository", "repo scoped: empty Repository")),
},
{
desc: "empty destination relative path",
req: &gitalypb.RenameRepositoryRequest{Repository: repo, RelativePath: ""},
+ exp: status.Error(codes.InvalidArgument, "destination relative path is empty"),
},
{
desc: "destination relative path contains path traversal",
req: &gitalypb.RenameRepositoryRequest{Repository: repo, RelativePath: "../usr/bin"},
+ exp: status.Error(codes.InvalidArgument, "GetRepoPath: relative path escapes root directory"),
+ },
+ {
+ desc: "repository storage doesn't exist",
+ req: &gitalypb.RenameRepositoryRequest{Repository: &gitalypb.Repository{StorageName: "stub", RelativePath: repo.RelativePath}, RelativePath: "../usr/bin"},
+ exp: status.Error(codes.InvalidArgument, gitalyOrPraefect(`GetStorageByName: no such storage: "stub"`, "repo scoped: invalid Repository")),
+ },
+ {
+ desc: "repository relative path doesn't exist",
+ req: &gitalypb.RenameRepositoryRequest{Repository: &gitalypb.Repository{StorageName: repo.StorageName, RelativePath: "stub"}, RelativePath: "../usr/bin"},
+ exp: status.Error(codes.NotFound, fmt.Sprintf(`GetRepoPath: not a git repository: "%s/stub"`, storagePath)),
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
_, err := client.RenameRepository(ctx, tc.req)
- testhelper.RequireGrpcCode(t, err, codes.InvalidArgument)
+ testhelper.RequireGrpcError(t, err, tc.exp)
})
}
}
diff --git a/internal/gitaly/service/repository/testhelper_test.go b/internal/gitaly/service/repository/testhelper_test.go
index 767eca3eb..df74b6fb6 100644
--- a/internal/gitaly/service/repository/testhelper_test.go
+++ b/internal/gitaly/service/repository/testhelper_test.go
@@ -192,3 +192,10 @@ func setupRepositoryServiceWithWorktree(ctx context.Context, t testing.TB, opts
return cfg, repo, repoPath, client
}
+
+func gitalyOrPraefect(gitalyMsg, praefectMsg string) string {
+ if testhelper.IsPraefectEnabled() {
+ return praefectMsg
+ }
+ return gitalyMsg
+}