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:
Diffstat (limited to 'internal/gitaly/service/repository/fullpath_test.go')
-rw-r--r--internal/gitaly/service/repository/fullpath_test.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/internal/gitaly/service/repository/fullpath_test.go b/internal/gitaly/service/repository/fullpath_test.go
index 071ce13a8..36b3947f7 100644
--- a/internal/gitaly/service/repository/fullpath_test.go
+++ b/internal/gitaly/service/repository/fullpath_test.go
@@ -13,6 +13,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
+ "google.golang.org/grpc/codes"
)
func TestSetFullPath(t *testing.T) {
@@ -145,3 +146,69 @@ func TestSetFullPath(t *testing.T) {
require.Equal(t, "replace", text.ChompBytes(fullPath))
})
}
+
+func TestFullPath(t *testing.T) {
+ t.Parallel()
+ ctx := testhelper.Context(t)
+
+ cfg, client := setupRepositoryServiceWithoutRepo(t)
+
+ t.Run("missing repository", func(t *testing.T) {
+ response, err := client.FullPath(ctx, &gitalypb.FullPathRequest{
+ Repository: nil,
+ })
+ require.Nil(t, response)
+ require.Error(t, err)
+ require.Contains(t, err.Error(), "empty Repository")
+ testhelper.RequireGrpcCode(t, err, codes.InvalidArgument)
+ })
+
+ t.Run("nonexistent repository", func(t *testing.T) {
+ repo := &gitalypb.Repository{
+ RelativePath: "/path/to/repo.git",
+ StorageName: cfg.Storages[0].Name,
+ }
+ repoPath, err := config.NewLocator(cfg).GetPath(repo)
+ require.NoError(t, err)
+
+ response, err := client.FullPath(ctx, &gitalypb.FullPathRequest{
+ Repository: repo,
+ })
+ require.Nil(t, response)
+
+ expectedErr := fmt.Sprintf("rpc error: code = NotFound desc = fetch config: rpc "+
+ "error: code = NotFound desc = GetRepoPath: not a git repository: %q", repoPath)
+ if testhelper.IsPraefectEnabled() {
+ expectedErr = `rpc error: code = NotFound desc = accessor call: route repository accessor: consistent storages: repository "default"/"/path/to/repo.git" not found`
+ }
+
+ require.EqualError(t, err, expectedErr)
+ testhelper.RequireGrpcCode(t, err, codes.NotFound)
+ })
+
+ t.Run("missing config", func(t *testing.T) {
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg)
+
+ configPath := filepath.Join(repoPath, "config")
+ require.NoError(t, os.Remove(configPath))
+
+ response, err := client.FullPath(ctx, &gitalypb.FullPathRequest{
+ Repository: repo,
+ })
+ require.Nil(t, response)
+ require.EqualError(t, err, "rpc error: code = Internal desc = fetch config: exit status 1")
+ testhelper.RequireGrpcCode(t, err, codes.Internal)
+ })
+
+ t.Run("existing config", func(t *testing.T) {
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg)
+
+ gittest.Exec(t, cfg, "-C", repoPath, "config", "--add", fullPathKey, "foo/bar")
+
+ response, err := client.FullPath(ctx, &gitalypb.FullPathRequest{
+ Repository: repo,
+ })
+ require.NoError(t, err)
+ testhelper.ProtoEqual(t, &gitalypb.FullPathResponse{Path: "foo/bar"}, response)
+ })
+}