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.go116
1 files changed, 116 insertions, 0 deletions
diff --git a/internal/gitaly/service/repository/fullpath_test.go b/internal/gitaly/service/repository/fullpath_test.go
new file mode 100644
index 000000000..92078d7df
--- /dev/null
+++ b/internal/gitaly/service/repository/fullpath_test.go
@@ -0,0 +1,116 @@
+package repository
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/helper"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/helper/text"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert"
+ "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
+)
+
+func TestSetFullPath(t *testing.T) {
+ t.Parallel()
+
+ cfg, client := setupRepositoryServiceWithoutRepo(t)
+
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
+ t.Run("missing repository", func(t *testing.T) {
+ response, err := client.SetFullPath(ctx, &gitalypb.SetFullPathRequest{
+ Repository: nil,
+ Path: "my/repo",
+ })
+ require.Nil(t, response)
+ require.Error(t, err)
+ require.Contains(t, err.Error(), "empty Repository")
+ })
+
+ t.Run("missing path", func(t *testing.T) {
+ repo, _, cleanup := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0])
+ defer cleanup()
+
+ response, err := client.SetFullPath(ctx, &gitalypb.SetFullPathRequest{
+ Repository: repo,
+ Path: "",
+ })
+ require.Nil(t, response)
+ testassert.GrpcEqualErr(t, helper.ErrInvalidArgumentf("no path provided"), err)
+ })
+
+ t.Run("invalid storage", func(t *testing.T) {
+ repo, _, cleanup := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0])
+ defer cleanup()
+ repo.StorageName = ""
+
+ response, err := client.SetFullPath(ctx, &gitalypb.SetFullPathRequest{
+ Repository: repo,
+ Path: "my/repo",
+ })
+ require.Nil(t, response)
+ // We can't assert a concrete error given that they're different when running with
+ // Praefect or without Praefect.
+ require.Error(t, err)
+ })
+
+ t.Run("nonexistent repo", 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.SetFullPath(ctx, &gitalypb.SetFullPathRequest{
+ Repository: repo,
+ Path: "my/repo",
+ })
+
+ require.Nil(t, response)
+
+ expectedErr := fmt.Sprintf("rpc error: code = Internal desc = writing config: rpc "+
+ "error: code = NotFound desc = GetRepoPath: not a git repository: %q", repoPath)
+ require.EqualError(t, err, expectedErr)
+ })
+
+ t.Run("normal repo", func(t *testing.T) {
+ repo, repoPath, cleanup := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0])
+ defer cleanup()
+
+ response, err := client.SetFullPath(ctx, &gitalypb.SetFullPathRequest{
+ Repository: repo,
+ Path: "foo/bar",
+ })
+ require.NoError(t, err)
+ testassert.ProtoEqual(t, &gitalypb.SetFullPathResponse{}, response)
+
+ fullPath := gittest.Exec(t, cfg, "-C", repoPath, "config", fullPathKey)
+ require.Equal(t, "foo/bar", text.ChompBytes(fullPath))
+ })
+
+ t.Run("missing config", func(t *testing.T) {
+ repo, repoPath, cleanup := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0])
+ defer cleanup()
+
+ configPath := filepath.Join(repoPath, "config")
+ require.NoError(t, os.Remove(configPath))
+
+ response, err := client.SetFullPath(ctx, &gitalypb.SetFullPathRequest{
+ Repository: repo,
+ Path: "foo/bar",
+ })
+ require.NoError(t, err)
+ testassert.ProtoEqual(t, &gitalypb.SetFullPathResponse{}, response)
+
+ fullPath := gittest.Exec(t, cfg, "-C", repoPath, "config", fullPathKey)
+ require.Equal(t, "foo/bar", text.ChompBytes(fullPath))
+ })
+}