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:30:49 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2022-02-23 11:47:18 +0300
commit27f942d96c96662b477ef6abf11c9b2003cea796 (patch)
treeb2aff80b11dce44ee1976292cf9021b3d6240a8c
parent3181a79fac67c1cb9e48312551ddc8e81ab66d42 (diff)
repository: Extend test coverage for OptimizeRepository 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/optimize.go3
-rw-r--r--internal/gitaly/service/repository/optimize_test.go36
2 files changed, 24 insertions, 15 deletions
diff --git a/internal/gitaly/service/repository/optimize.go b/internal/gitaly/service/repository/optimize.go
index bbf1ee406..8ea1555ab 100644
--- a/internal/gitaly/service/repository/optimize.go
+++ b/internal/gitaly/service/repository/optimize.go
@@ -3,6 +3,7 @@ package repository
import (
"context"
+ gitalyerrors "gitlab.com/gitlab-org/gitaly/v14/internal/errors"
"gitlab.com/gitlab-org/gitaly/v14/internal/helper"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
)
@@ -23,7 +24,7 @@ func (s *server) OptimizeRepository(ctx context.Context, in *gitalypb.OptimizeRe
func (s *server) validateOptimizeRepositoryRequest(in *gitalypb.OptimizeRepositoryRequest) error {
if in.GetRepository() == nil {
- return helper.ErrInvalidArgumentf("empty repository")
+ return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
}
_, err := s.locator.GetRepoPath(in.GetRepository())
diff --git a/internal/gitaly/service/repository/optimize_test.go b/internal/gitaly/service/repository/optimize_test.go
index c35ffa924..0bc1932d5 100644
--- a/internal/gitaly/service/repository/optimize_test.go
+++ b/internal/gitaly/service/repository/optimize_test.go
@@ -2,6 +2,7 @@ package repository
import (
"bytes"
+ "fmt"
"os"
"path/filepath"
"testing"
@@ -14,6 +15,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"google.golang.org/grpc/codes"
+ "google.golang.org/grpc/status"
)
func getNewestPackfileModtime(t *testing.T, repoPath string) time.Time {
@@ -151,27 +153,33 @@ func TestOptimizeRepositoryValidation(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- _, repo, _, client := setupRepositoryService(ctx, t)
+ cfg, repo, _, client := setupRepositoryService(ctx, t)
testCases := []struct {
- desc string
- repo *gitalypb.Repository
- expectedErrorCode codes.Code
+ desc string
+ repo *gitalypb.Repository
+ exp error
}{
{
- desc: "empty repository",
- repo: nil,
- expectedErrorCode: codes.InvalidArgument,
+ desc: "empty repository",
+ repo: nil,
+ exp: status.Error(codes.InvalidArgument, gitalyOrPraefect("empty Repository", "repo scoped: empty Repository")),
},
{
- desc: "invalid repository storage",
- repo: &gitalypb.Repository{StorageName: "non-existent", RelativePath: repo.GetRelativePath()},
- expectedErrorCode: codes.InvalidArgument,
+ desc: "invalid repository storage",
+ repo: &gitalypb.Repository{StorageName: "non-existent", RelativePath: repo.GetRelativePath()},
+ exp: status.Error(codes.InvalidArgument, gitalyOrPraefect(`GetStorageByName: no such storage: "non-existent"`, "repo scoped: invalid Repository")),
},
{
- desc: "invalid repository path",
- repo: &gitalypb.Repository{StorageName: repo.GetStorageName(), RelativePath: "/path/not/exist"},
- expectedErrorCode: codes.NotFound,
+ desc: "invalid repository path",
+ repo: &gitalypb.Repository{StorageName: repo.GetStorageName(), RelativePath: "path/not/exist"},
+ exp: status.Error(
+ codes.NotFound,
+ gitalyOrPraefect(
+ fmt.Sprintf(`GetRepoPath: not a git repository: "%s/path/not/exist"`, cfg.Storages[0].Path),
+ `mutator call: route repository mutator: get repository id: repository "default"/"path/not/exist" not found`,
+ ),
+ ),
},
}
@@ -179,7 +187,7 @@ func TestOptimizeRepositoryValidation(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
_, err := client.OptimizeRepository(ctx, &gitalypb.OptimizeRepositoryRequest{Repository: tc.repo})
require.Error(t, err)
- testhelper.RequireGrpcCode(t, err, tc.expectedErrorCode)
+ testhelper.RequireGrpcError(t, err, tc.exp)
})
}