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:
authorSami Hiltunen <shiltunen@gitlab.com>2022-02-02 13:32:38 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2022-02-02 13:32:38 +0300
commitd57320dd13509ffad631b8a60e8943008c46dee0 (patch)
tree34e7e03a851ff75679e3deaba4b3565a2eade55d
parentb664d34ba4a0f359150614dc7a85ad0bf2554d6d (diff)
parentf718e57df8688134e550179f0c9e5cc8dd65ce11 (diff)
Merge branch 'smh-create-repo-ref' into 'master'
Disable metadata creation hack in ref service tests See merge request gitlab-org/gitaly!4281
-rw-r--r--internal/gitaly/service/ref/branches_test.go7
-rw-r--r--internal/gitaly/service/ref/delete_refs_test.go26
-rw-r--r--internal/gitaly/service/ref/find_all_tags_test.go26
-rw-r--r--internal/gitaly/service/ref/find_refs_by_oid_test.go24
-rw-r--r--internal/gitaly/service/ref/list_refs_test.go46
-rw-r--r--internal/gitaly/service/ref/pack_refs_test.go2
-rw-r--r--internal/gitaly/service/ref/refexists_test.go5
-rw-r--r--internal/gitaly/service/ref/refs_test.go63
-rw-r--r--internal/gitaly/service/ref/remote_branches_test.go6
-rw-r--r--internal/gitaly/service/ref/tag_messages_test.go2
-rw-r--r--internal/gitaly/service/ref/tag_signatures_test.go2
-rw-r--r--internal/gitaly/service/ref/testhelper_test.go20
12 files changed, 129 insertions, 100 deletions
diff --git a/internal/gitaly/service/ref/branches_test.go b/internal/gitaly/service/ref/branches_test.go
index aef42b4ad..3e7088fda 100644
--- a/internal/gitaly/service/ref/branches_test.go
+++ b/internal/gitaly/service/ref/branches_test.go
@@ -14,7 +14,7 @@ import (
func TestSuccessfulFindBranchRequest(t *testing.T) {
ctx := testhelper.Context(t)
- cfg, repoProto, _, client := setupRefService(t)
+ cfg, repoProto, _, client := setupRefService(ctx, t)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
@@ -71,7 +71,6 @@ func TestSuccessfulFindBranchRequest(t *testing.T) {
Repository: repoProto,
Name: []byte(testCase.branchName),
}
- ctx := testhelper.Context(t)
response, err := client.FindBranch(ctx, request)
@@ -82,7 +81,8 @@ func TestSuccessfulFindBranchRequest(t *testing.T) {
}
func TestFailedFindBranchRequest(t *testing.T) {
- _, repo, _, client := setupRefService(t)
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRefService(ctx, t)
testCases := []struct {
desc string
@@ -102,7 +102,6 @@ func TestFailedFindBranchRequest(t *testing.T) {
Repository: repo,
Name: []byte(testCase.branchName),
}
- ctx := testhelper.Context(t)
_, err := client.FindBranch(ctx, request)
testhelper.RequireGrpcCode(t, err, testCase.code)
diff --git a/internal/gitaly/service/ref/delete_refs_test.go b/internal/gitaly/service/ref/delete_refs_test.go
index ba1a6d654..a922685fc 100644
--- a/internal/gitaly/service/ref/delete_refs_test.go
+++ b/internal/gitaly/service/ref/delete_refs_test.go
@@ -9,6 +9,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v14/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/service"
hookservice "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/service/hook"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/service/repository"
"gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v14/internal/metadata"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
@@ -46,7 +47,9 @@ func TestDeleteRefs_successful(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
- repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/delete/a", "b83d6e391c22777fca1ed3012fce84f633d7fed0")
gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/also-delete/b", "1b12f15a11fc6e62177bef08f47bc7b5ce50b141")
@@ -92,8 +95,19 @@ func TestDeleteRefs_transaction(t *testing.T) {
deps.GetTxManager(),
deps.GetCatfileCache(),
))
+ gitalypb.RegisterRepositoryServiceServer(srv, repository.NewServer(
+ deps.GetCfg(),
+ deps.GetRubyServer(),
+ deps.GetLocator(),
+ deps.GetTxManager(),
+ deps.GetGitCmdFactory(),
+ deps.GetCatfileCache(),
+ deps.GetConnsPool(),
+ deps.GetGit2goExecutor(),
+ ))
gitalypb.RegisterHookServiceServer(srv, hookservice.NewServer(deps.GetHookManager(), deps.GetGitCmdFactory(), deps.GetPackObjectsCache()))
- }, testserver.WithTransactionManager(txManager))
+ }, testserver.WithTransactionManager(txManager), testserver.WithDisableMetadataForceCreation())
+ cfg.SocketPath = addr
client, conn := newRefServiceClient(t, addr)
t.Cleanup(func() { conn.Close() })
@@ -123,9 +137,11 @@ func TestDeleteRefs_transaction(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
+ repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
txManager.Reset()
- repo, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
tc.request.Repository = repo
response, err := client.DeleteRefs(ctx, tc.request)
@@ -141,7 +157,7 @@ func TestDeleteRefs_invalidRefFormat(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- _, repo, _, client := setupRefService(t)
+ _, repo, _, client := setupRefService(ctx, t)
request := &gitalypb.DeleteRefsRequest{
Repository: repo,
@@ -158,7 +174,7 @@ func TestDeleteRefs_validation(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- _, repo, _, client := setupRefService(t)
+ _, repo, _, client := setupRefService(ctx, t)
testCases := []struct {
desc string
diff --git a/internal/gitaly/service/ref/find_all_tags_test.go b/internal/gitaly/service/ref/find_all_tags_test.go
index d5d042111..487790b7d 100644
--- a/internal/gitaly/service/ref/find_all_tags_test.go
+++ b/internal/gitaly/service/ref/find_all_tags_test.go
@@ -27,11 +27,9 @@ import (
)
func TestFindAllTags_successful(t *testing.T) {
- cfg, client := setupRefServiceWithoutRepo(t)
-
- repoProto, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
- repo := localrepo.NewTestRepo(t, cfg, repoProto)
ctx := testhelper.Context(t)
+ cfg, repoProto, repoPath, client := setupRefService(ctx, t)
+ repo := localrepo.NewTestRepo(t, cfg, repoProto)
// reconstruct the v1.1.2 tag from patches to test truncated tag message
// with partial PGP block
@@ -226,7 +224,7 @@ func TestFindAllTags_simpleNestedTags(t *testing.T) {
cfg, client := setupRefServiceWithoutRepo(t)
ctx := testhelper.Context(t)
- repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg)
commitID := gittest.WriteCommit(t, cfg, repoPath,
gittest.WithParents(),
@@ -275,10 +273,11 @@ func TestFindAllTags_simpleNestedTags(t *testing.T) {
func TestFindAllTags_duplicateAnnotatedTags(t *testing.T) {
cfg, client := setupRefServiceWithoutRepo(t)
- repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
- repo := localrepo.NewTestRepo(t, cfg, repoProto)
ctx := testhelper.Context(t)
+ repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg)
+ repo := localrepo.NewTestRepo(t, cfg, repoProto)
+
commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithParents())
date := time.Unix(12345, 0)
dateOffset := date.Format("-0700")
@@ -354,10 +353,9 @@ func TestFindAllTags_duplicateAnnotatedTags(t *testing.T) {
}
func TestFindAllTags_nestedTags(t *testing.T) {
- cfg, client := setupRefServiceWithoutRepo(t)
ctx := testhelper.Context(t)
+ cfg, repoProto, repoPath, client := setupRefService(ctx, t)
- repoProto, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
repo := localrepo.NewTestRepo(t, cfg, repoProto)
blobID := git.ObjectID("faaf198af3a36dbf41961466703cc1d47c61d051")
@@ -510,9 +508,7 @@ func TestFindAllTags_pagination(t *testing.T) {
}
func testFindAllTagsPagination(t *testing.T, ctx context.Context) {
- cfg, client := setupRefServiceWithoutRepo(t)
-
- repoProto, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ cfg, repoProto, repoPath, client := setupRefService(ctx, t)
catfileCache := catfile.NewCache(cfg)
defer catfileCache.Stop()
@@ -634,10 +630,8 @@ func testFindAllTagsPagination(t *testing.T, ctx context.Context) {
}
func TestFindAllTags_sorted(t *testing.T) {
- cfg, client := setupRefServiceWithoutRepo(t)
ctx := testhelper.Context(t)
-
- repoProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ cfg, repoProto, _, client := setupRefService(ctx, t)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
headCommit, err := repo.ReadCommit(ctx, "HEAD")
@@ -736,7 +730,7 @@ func TestFindAllTags_sorted(t *testing.T) {
})
t.Run("no tags", func(t *testing.T) {
- repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ repoProto, _ := gittest.CreateRepository(ctx, t, cfg)
c, err := client.FindAllTags(ctx, &gitalypb.FindAllTagsRequest{
Repository: repoProto,
SortBy: &gitalypb.FindAllTagsRequest_SortBy{Key: gitalypb.FindAllTagsRequest_SortBy_REFNAME},
diff --git a/internal/gitaly/service/ref/find_refs_by_oid_test.go b/internal/gitaly/service/ref/find_refs_by_oid_test.go
index 47481b415..8d657ce97 100644
--- a/internal/gitaly/service/ref/find_refs_by_oid_test.go
+++ b/internal/gitaly/service/ref/find_refs_by_oid_test.go
@@ -17,7 +17,7 @@ import (
func TestFindRefsByOID_successful(t *testing.T) {
ctx := testhelper.Context(t)
- cfg, repo, repoPath, client := setupRefService(t)
+ cfg, repo, repoPath, client := setupRefService(ctx, t)
oid := gittest.WriteCommit(t, cfg, repoPath)
@@ -126,7 +126,9 @@ func TestFindRefsByOID_failure(t *testing.T) {
{
desc: "no ref exists for OID",
setup: func(t *testing.T) (*gitalypb.FindRefsByOIDRequest, error) {
- repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
oid := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("no ref exists for OID"))
return &gitalypb.FindRefsByOIDRequest{
@@ -138,7 +140,9 @@ func TestFindRefsByOID_failure(t *testing.T) {
{
desc: "repository is corrupted",
setup: func(t *testing.T) (*gitalypb.FindRefsByOIDRequest, error) {
- repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
oid := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("no ref exists for OID"))
gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/heads/corrupted-repo-branch", oid.String())
@@ -153,7 +157,9 @@ func TestFindRefsByOID_failure(t *testing.T) {
{
desc: "repository is missing",
setup: func(t *testing.T) (*gitalypb.FindRefsByOIDRequest, error) {
- repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
oid := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("repository is missing"))
require.NoError(t, os.RemoveAll(repoPath))
@@ -166,7 +172,9 @@ func TestFindRefsByOID_failure(t *testing.T) {
{
desc: "oid is not a commit",
setup: func(t *testing.T) (*gitalypb.FindRefsByOIDRequest, error) {
- repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
oid := gittest.WriteBlob(t, cfg, repoPath, []byte("the blob"))
return &gitalypb.FindRefsByOIDRequest{
@@ -178,7 +186,9 @@ func TestFindRefsByOID_failure(t *testing.T) {
{
desc: "oid prefix too short",
setup: func(t *testing.T) (*gitalypb.FindRefsByOIDRequest, error) {
- repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
oid := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("oid prefix too short"))
gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/heads/short-oid", oid.String())
@@ -204,7 +214,7 @@ func TestFindRefsByOID_failure(t *testing.T) {
func TestFindRefsByOID_validation(t *testing.T) {
ctx := testhelper.Context(t)
- _, repo, _, client := setupRefService(t)
+ _, repo, _, client := setupRefService(ctx, t)
testCases := map[string]struct {
req *gitalypb.FindRefsByOIDRequest
diff --git a/internal/gitaly/service/ref/list_refs_test.go b/internal/gitaly/service/ref/list_refs_test.go
index e3cc551a1..31eae96a2 100644
--- a/internal/gitaly/service/ref/list_refs_test.go
+++ b/internal/gitaly/service/ref/list_refs_test.go
@@ -6,6 +6,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/git"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v14/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
@@ -14,30 +15,31 @@ import (
)
func TestServer_ListRefs(t *testing.T) {
- cfg, _, _, client := setupRefService(t)
ctx := testhelper.Context(t)
+ cfg, _, _, client := setupRefService(ctx, t)
- storagePath, ok := cfg.StoragePath("default")
- require.True(t, ok)
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg)
+ // Checking out a worktree in an empty repository is not possible, so we must first write an empty commit.
+ gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch(git.DefaultBranch), gittest.WithParents())
+ gittest.AddWorktree(t, cfg, repoPath, "worktree")
+ repoPath = filepath.Join(repoPath, "worktree")
+ // The worktree is detached, checkout the main so the branch pointer advances
+ // as we commit.
+ gittest.Exec(t, cfg, "-C", repoPath, "checkout", "main")
- const relativePath = "repository-1"
- repoPath := filepath.Join(storagePath, relativePath)
-
- gittest.Exec(t, cfg, "init", repoPath)
- gittest.Exec(t, cfg, "-C", repoPath, "commit", "--allow-empty", "-m", "initial")
- oldCommit := text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "refs/heads/master"))
+ oldCommit := text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "refs/heads/main"))
gittest.Exec(t, cfg, "-C", repoPath, "commit", "--allow-empty", "-m", "commit message")
gittest.Exec(t, cfg, "-C", repoPath, "commit", "--amend", "--date", "Wed Feb 16 14:01 2011 +0100", "--allow-empty", "--no-edit")
- commit := text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "refs/heads/master"))
+ commit := text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "refs/heads/main"))
for _, cmd := range [][]string{
- {"update-ref", "refs/heads/master", commit},
+ {"update-ref", "refs/heads/main", commit},
{"tag", "lightweight-tag", commit},
- {"tag", "-m", "tag message", "annotated-tag", "refs/heads/master"},
- {"symbolic-ref", "refs/heads/symbolic", "refs/heads/master"},
+ {"tag", "-m", "tag message", "annotated-tag", "refs/heads/main"},
+ {"symbolic-ref", "refs/heads/symbolic", "refs/heads/main"},
{"update-ref", "refs/remote/remote-name/remote-branch", commit},
- {"symbolic-ref", "HEAD", "refs/heads/master"},
+ {"symbolic-ref", "HEAD", "refs/heads/main"},
{"update-ref", "refs/heads/old", oldCommit},
} {
gittest.Exec(t, cfg, append([]string{"-C", repoPath}, cmd...)...)
@@ -45,8 +47,6 @@ func TestServer_ListRefs(t *testing.T) {
annotatedTagOID := text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "annotated-tag"))
- repo := &gitalypb.Repository{StorageName: "default", RelativePath: filepath.Join(relativePath, ".git")}
-
for _, tc := range []struct {
desc string
request *gitalypb.ListRefsRequest
@@ -102,16 +102,16 @@ func TestServer_ListRefs(t *testing.T) {
},
},
{
- desc: "not found and master",
+ desc: "not found and main",
request: &gitalypb.ListRefsRequest{
Repository: repo,
Patterns: [][]byte{
[]byte("this-pattern-does-not-match-anything"),
- []byte("refs/heads/master"),
+ []byte("refs/heads/main"),
},
},
expected: []*gitalypb.ListRefsResponse_Reference{
- {Name: []byte("refs/heads/master"), Target: commit},
+ {Name: []byte("refs/heads/main"), Target: commit},
},
},
{
@@ -121,7 +121,7 @@ func TestServer_ListRefs(t *testing.T) {
Patterns: [][]byte{[]byte("refs/")},
},
expected: []*gitalypb.ListRefsResponse_Reference{
- {Name: []byte("refs/heads/master"), Target: commit},
+ {Name: []byte("refs/heads/main"), Target: commit},
{Name: []byte("refs/heads/old"), Target: oldCommit},
{Name: []byte("refs/heads/symbolic"), Target: commit},
{Name: []byte("refs/remote/remote-name/remote-branch"), Target: commit},
@@ -141,7 +141,7 @@ func TestServer_ListRefs(t *testing.T) {
},
expected: []*gitalypb.ListRefsResponse_Reference{
{Name: []byte("refs/heads/old"), Target: oldCommit},
- {Name: []byte("refs/heads/master"), Target: commit},
+ {Name: []byte("refs/heads/main"), Target: commit},
{Name: []byte("refs/heads/symbolic"), Target: commit},
},
},
@@ -152,7 +152,7 @@ func TestServer_ListRefs(t *testing.T) {
Patterns: [][]byte{[]byte("refs/heads/*"), []byte("refs/tags/*")},
},
expected: []*gitalypb.ListRefsResponse_Reference{
- {Name: []byte("refs/heads/master"), Target: commit},
+ {Name: []byte("refs/heads/main"), Target: commit},
{Name: []byte("refs/heads/old"), Target: oldCommit},
{Name: []byte("refs/heads/symbolic"), Target: commit},
{Name: []byte("refs/tags/annotated-tag"), Target: annotatedTagOID},
@@ -168,7 +168,7 @@ func TestServer_ListRefs(t *testing.T) {
},
expected: []*gitalypb.ListRefsResponse_Reference{
{Name: []byte("HEAD"), Target: commit},
- {Name: []byte("refs/heads/master"), Target: commit},
+ {Name: []byte("refs/heads/main"), Target: commit},
{Name: []byte("refs/heads/old"), Target: oldCommit},
{Name: []byte("refs/heads/symbolic"), Target: commit},
{Name: []byte("refs/tags/annotated-tag"), Target: annotatedTagOID},
diff --git a/internal/gitaly/service/ref/pack_refs_test.go b/internal/gitaly/service/ref/pack_refs_test.go
index 779f459fa..d7de1a17f 100644
--- a/internal/gitaly/service/ref/pack_refs_test.go
+++ b/internal/gitaly/service/ref/pack_refs_test.go
@@ -20,7 +20,7 @@ import (
func TestPackRefsSuccessfulRequest(t *testing.T) {
ctx := testhelper.Context(t)
- cfg, repoProto, repoPath, client := setupRefService(t)
+ cfg, repoProto, repoPath, client := setupRefService(ctx, t)
packedRefs := linesInPackfile(t, repoPath)
diff --git a/internal/gitaly/service/ref/refexists_test.go b/internal/gitaly/service/ref/refexists_test.go
index aab12156a..4e87c19ec 100644
--- a/internal/gitaly/service/ref/refexists_test.go
+++ b/internal/gitaly/service/ref/refexists_test.go
@@ -10,7 +10,8 @@ import (
)
func TestRefExists(t *testing.T) {
- _, repo, _, client := setupRefService(t)
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRefService(ctx, t)
badRepo := &gitalypb.Repository{StorageName: "invalid", RelativePath: "/etc/"}
@@ -37,8 +38,6 @@ func TestRefExists(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- ctx := testhelper.Context(t)
-
req := &gitalypb.RefExistsRequest{Repository: tt.repo, Ref: []byte(tt.ref)}
got, err := client.RefExists(ctx, req)
diff --git a/internal/gitaly/service/ref/refs_test.go b/internal/gitaly/service/ref/refs_test.go
index 78679c777..7278f7767 100644
--- a/internal/gitaly/service/ref/refs_test.go
+++ b/internal/gitaly/service/ref/refs_test.go
@@ -33,10 +33,10 @@ func containsRef(refs [][]byte, ref string) bool {
}
func TestSuccessfulFindAllBranchNames(t *testing.T) {
- _, repo, _, client := setupRefService(t)
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRefService(ctx, t)
rpcRequest := &gitalypb.FindAllBranchNamesRequest{Repository: repo}
- ctx := testhelper.Context(t)
c, err := client.FindAllBranchNames(ctx, rpcRequest)
require.NoError(t, err)
@@ -58,8 +58,8 @@ func TestSuccessfulFindAllBranchNames(t *testing.T) {
}
func TestFindAllBranchNamesVeryLargeResponse(t *testing.T) {
- cfg, repoProto, _, client := setupRefService(t)
ctx := testhelper.Context(t)
+ cfg, repoProto, _, client := setupRefService(ctx, t)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
updater, err := updateref.New(ctx, repo)
@@ -143,10 +143,10 @@ func TestInvalidRepoFindAllBranchNamesRequest(t *testing.T) {
}
func TestSuccessfulFindAllTagNames(t *testing.T) {
- _, repo, _, client := setupRefService(t)
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRefService(ctx, t)
rpcRequest := &gitalypb.FindAllTagNamesRequest{Repository: repo}
- ctx := testhelper.Context(t)
c, err := client.FindAllTagNames(ctx, rpcRequest)
require.NoError(t, err)
@@ -205,14 +205,14 @@ func TestInvalidRepoFindAllTagNamesRequest(t *testing.T) {
}
func TestSuccessfulFindDefaultBranchName(t *testing.T) {
- cfg, repo, repoPath, client := setupRefService(t)
+ ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRefService(ctx, t)
rpcRequest := &gitalypb.FindDefaultBranchNameRequest{Repository: repo}
// The testing repository has no main branch, so we create it and update
// HEAD to it
gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/heads/main", "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863")
gittest.Exec(t, cfg, "-C", repoPath, "symbolic-ref", "HEAD", "refs/heads/main")
- ctx := testhelper.Context(t)
r, err := client.FindDefaultBranchName(ctx, rpcRequest)
require.NoError(t, err)
@@ -220,9 +220,9 @@ func TestSuccessfulFindDefaultBranchName(t *testing.T) {
}
func TestSuccessfulFindDefaultBranchNameLegacy(t *testing.T) {
- _, repo, _, client := setupRefService(t)
- rpcRequest := &gitalypb.FindDefaultBranchNameRequest{Repository: repo}
ctx := testhelper.Context(t)
+ _, repo, _, client := setupRefService(ctx, t)
+ rpcRequest := &gitalypb.FindDefaultBranchNameRequest{Repository: repo}
r, err := client.FindDefaultBranchName(ctx, rpcRequest)
require.NoError(t, err)
@@ -253,10 +253,10 @@ func TestInvalidRepoFindDefaultBranchNameRequest(t *testing.T) {
}
func TestSuccessfulFindLocalBranches(t *testing.T) {
- _, repo, _, client := setupRefService(t)
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRefService(ctx, t)
rpcRequest := &gitalypb.FindLocalBranchesRequest{Repository: repo}
- ctx := testhelper.Context(t)
c, err := client.FindLocalBranches(ctx, rpcRequest)
require.NoError(t, err)
@@ -297,7 +297,7 @@ func TestFindLocalBranches_huge_committer(t *testing.T) {
}
func testFindLocalBranchesHugeCommitter(t *testing.T, ctx context.Context) {
- cfg, repo, repoPath, client := setupRefService(t)
+ cfg, repo, repoPath, client := setupRefService(ctx, t)
gittest.WriteCommit(t, cfg, repoPath,
gittest.WithBranch("refs/heads/improve/awesome"),
@@ -323,7 +323,7 @@ func TestFindLocalBranchesPagination(t *testing.T) {
}
func testFindLocalBranchesPagination(t *testing.T, ctx context.Context) {
- _, repo, _, client := setupRefService(t)
+ _, repo, _, client := setupRefService(ctx, t)
limit := 1
rpcRequest := &gitalypb.FindLocalBranchesRequest{
@@ -375,7 +375,7 @@ func TestFindLocalBranchesPaginationSequence(t *testing.T) {
}
func testFindLocalBranchesPaginationSequence(t *testing.T, ctx context.Context) {
- _, repo, _, client := setupRefService(t)
+ _, repo, _, client := setupRefService(ctx, t)
limit := 2
firstRPCRequest := &gitalypb.FindLocalBranchesRequest{
@@ -428,7 +428,7 @@ func TestFindLocalBranchesPaginationWithIncorrectToken(t *testing.T) {
}
func testFindLocalBranchesPaginationWithIncorrectToken(t *testing.T, ctx context.Context) {
- _, repo, _, client := setupRefService(t)
+ _, repo, _, client := setupRefService(ctx, t)
limit := 1
rpcRequest := &gitalypb.FindLocalBranchesRequest{
@@ -526,7 +526,7 @@ func testFindLocalBranchesSort(t *testing.T, ctx context.Context) {
},
}
- _, repo, _, client := setupRefService(t)
+ _, repo, _, client := setupRefService(ctx, t)
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
@@ -574,7 +574,8 @@ func TestEmptyFindLocalBranchesRequest(t *testing.T) {
}
func TestSuccessfulFindAllBranchesRequest(t *testing.T) {
- cfg, repo, repoPath, client := setupRefService(t)
+ ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRefService(ctx, t)
remoteBranch := &gitalypb.FindAllBranchesResponse_Branch{
Name: []byte("refs/remotes/origin/fake-remote-branch"),
@@ -604,7 +605,6 @@ func TestSuccessfulFindAllBranchesRequest(t *testing.T) {
gittest.WriteRef(t, cfg, repoPath, "refs/remotes/origin/fake-remote-branch", git.ObjectID(remoteBranch.Target.Id))
request := &gitalypb.FindAllBranchesRequest{Repository: repo}
- ctx := testhelper.Context(t)
c, err := client.FindAllBranches(ctx, request)
require.NoError(t, err)
@@ -624,10 +624,10 @@ func TestSuccessfulFindAllBranchesRequest(t *testing.T) {
}
func TestSuccessfulFindAllBranchesRequestWithMergedBranches(t *testing.T) {
- cfg, repoProto, repoPath, client := setupRefService(t)
+ ctx := testhelper.Context(t)
+ cfg, repoProto, repoPath, client := setupRefService(ctx, t)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
- ctx := testhelper.Context(t)
localRefs := gittest.Exec(t, cfg, "-C", repoPath, "for-each-ref", "--format=%(refname:strip=2)", "refs/heads")
for _, ref := range strings.Split(string(localRefs), "\n") {
@@ -762,7 +762,8 @@ func readFindAllBranchesResponsesFromClient(t *testing.T, c gitalypb.RefService_
}
func TestListTagNamesContainingCommit(t *testing.T) {
- _, repoProto, _, client := setupRefService(t)
+ ctx := testhelper.Context(t)
+ _, repoProto, _, client := setupRefService(ctx, t)
testCases := []struct {
description string
@@ -799,8 +800,6 @@ func TestListTagNamesContainingCommit(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
- ctx := testhelper.Context(t)
-
request := &gitalypb.ListTagNamesContainingCommitRequest{Repository: repoProto, CommitId: tc.commitID}
c, err := client.ListTagNamesContainingCommit(ctx, request)
@@ -831,7 +830,8 @@ func TestListTagNamesContainingCommit(t *testing.T) {
}
func TestListBranchNamesContainingCommit(t *testing.T) {
- _, repo, _, client := setupRefService(t)
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRefService(ctx, t)
testCases := []struct {
description string
@@ -885,8 +885,6 @@ func TestListBranchNamesContainingCommit(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
- ctx := testhelper.Context(t)
-
request := &gitalypb.ListBranchNamesContainingCommitRequest{Repository: repo, CommitId: tc.commitID}
c, err := client.ListBranchNamesContainingCommit(ctx, request)
@@ -917,7 +915,8 @@ func TestListBranchNamesContainingCommit(t *testing.T) {
}
func TestSuccessfulFindTagRequest(t *testing.T) {
- cfg, repoProto, repoPath, client := setupRefService(t)
+ ctx := testhelper.Context(t)
+ cfg, repoProto, repoPath, client := setupRefService(ctx, t)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
@@ -925,7 +924,6 @@ func TestSuccessfulFindTagRequest(t *testing.T) {
commitID := git.ObjectID("6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9")
gitCommit := testhelper.GitLabTestCommit(commitID.String())
- ctx := testhelper.Context(t)
bigCommitID := gittest.WriteCommit(t, cfg, repoPath,
gittest.WithBranch("local-big-commits"),
@@ -1081,14 +1079,13 @@ func TestSuccessfulFindTagRequest(t *testing.T) {
}
func TestFindTagNestedTag(t *testing.T) {
- cfg, client := setupRefServiceWithoutRepo(t)
+ ctx := testhelper.Context(t)
+ cfg, repoProto, repoPath, client := setupRefService(ctx, t)
- repoProto, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
repo := localrepo.NewTestRepo(t, cfg, repoProto)
blobID := git.ObjectID("faaf198af3a36dbf41961466703cc1d47c61d051")
commitID := git.ObjectID("6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9")
- ctx := testhelper.Context(t)
testCases := []struct {
description string
@@ -1176,7 +1173,8 @@ func TestFindTagNestedTag(t *testing.T) {
}
func TestInvalidFindTagRequest(t *testing.T) {
- _, repo, _, client := setupRefService(t)
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRefService(ctx, t)
testCases := []struct {
desc string
@@ -1205,7 +1203,6 @@ func TestInvalidFindTagRequest(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- ctx := testhelper.Context(t)
_, err := client.FindTag(ctx, tc.request)
testhelper.RequireGrpcCode(t, err, codes.InvalidArgument)
})
diff --git a/internal/gitaly/service/ref/remote_branches_test.go b/internal/gitaly/service/ref/remote_branches_test.go
index c20205e41..9fa8ba90c 100644
--- a/internal/gitaly/service/ref/remote_branches_test.go
+++ b/internal/gitaly/service/ref/remote_branches_test.go
@@ -17,7 +17,7 @@ import (
func TestSuccessfulFindAllRemoteBranchesRequest(t *testing.T) {
ctx := testhelper.Context(t)
- cfg, repoProto, repoPath, client := setupRefService(t)
+ cfg, repoProto, repoPath, client := setupRefService(ctx, t)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
@@ -73,7 +73,8 @@ func TestSuccessfulFindAllRemoteBranchesRequest(t *testing.T) {
}
func TestInvalidFindAllRemoteBranchesRequest(t *testing.T) {
- _, repo, _, client := setupRefService(t)
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRefService(ctx, t)
testCases := []struct {
description string
@@ -100,7 +101,6 @@ func TestInvalidFindAllRemoteBranchesRequest(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
- ctx := testhelper.Context(t)
c, err := client.FindAllRemoteBranches(ctx, tc.request)
require.NoError(t, err)
diff --git a/internal/gitaly/service/ref/tag_messages_test.go b/internal/gitaly/service/ref/tag_messages_test.go
index 70c4390d4..36d236d4e 100644
--- a/internal/gitaly/service/ref/tag_messages_test.go
+++ b/internal/gitaly/service/ref/tag_messages_test.go
@@ -14,8 +14,8 @@ import (
)
func TestSuccessfulGetTagMessagesRequest(t *testing.T) {
- cfg, repo, repoPath, client := setupRefService(t)
ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRefService(ctx, t)
message1 := strings.Repeat("a", helper.MaxCommitOrTagMessageSize*2)
message2 := strings.Repeat("b", helper.MaxCommitOrTagMessageSize)
diff --git a/internal/gitaly/service/ref/tag_signatures_test.go b/internal/gitaly/service/ref/tag_signatures_test.go
index 89a6ec389..3e0b7252c 100644
--- a/internal/gitaly/service/ref/tag_signatures_test.go
+++ b/internal/gitaly/service/ref/tag_signatures_test.go
@@ -18,7 +18,7 @@ import (
func TestGetTagSignatures(t *testing.T) {
ctx := testhelper.Context(t)
- cfg, repoProto, repoPath, client := setupRefService(t)
+ cfg, repoProto, repoPath, client := setupRefService(ctx, t)
message1 := strings.Repeat("a", helper.MaxCommitOrTagMessageSize) + "\n"
signature1 := string(testhelper.MustReadFile(t, "testdata/tag-1e292f8fedd741b75372e19097c76d327140c312-signature"))
diff --git a/internal/gitaly/service/ref/testhelper_test.go b/internal/gitaly/service/ref/testhelper_test.go
index 75b2e24c7..7fc6e0485 100644
--- a/internal/gitaly/service/ref/testhelper_test.go
+++ b/internal/gitaly/service/ref/testhelper_test.go
@@ -2,6 +2,7 @@ package ref
import (
"bytes"
+ "context"
"testing"
"github.com/stretchr/testify/require"
@@ -9,6 +10,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/service"
hookservice "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/service/hook"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/service/repository"
"gitlab.com/gitlab-org/gitaly/v14/internal/helper/lines"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg"
@@ -32,9 +34,11 @@ func TestMain(m *testing.M) {
}))
}
-func setupRefService(t testing.TB) (config.Cfg, *gitalypb.Repository, string, gitalypb.RefServiceClient) {
+func setupRefService(ctx context.Context, t testing.TB) (config.Cfg, *gitalypb.Repository, string, gitalypb.RefServiceClient) {
cfg, client := setupRefServiceWithoutRepo(t)
- repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
return cfg, repo, repoPath, client
}
@@ -61,7 +65,17 @@ func runRefServiceServer(t testing.TB, cfg config.Cfg) string {
deps.GetCatfileCache(),
))
gitalypb.RegisterHookServiceServer(srv, hookservice.NewServer(deps.GetHookManager(), deps.GetGitCmdFactory(), deps.GetPackObjectsCache()))
- })
+ gitalypb.RegisterRepositoryServiceServer(srv, repository.NewServer(
+ deps.GetCfg(),
+ deps.GetRubyServer(),
+ deps.GetLocator(),
+ deps.GetTxManager(),
+ deps.GetGitCmdFactory(),
+ deps.GetCatfileCache(),
+ deps.GetConnsPool(),
+ deps.GetGit2goExecutor(),
+ ))
+ }, testserver.WithDisableMetadataForceCreation())
}
func newRefServiceClient(t testing.TB, serverSocketPath string) (gitalypb.RefServiceClient, *grpc.ClientConn) {