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-01-20 13:02:42 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2022-02-01 12:28:01 +0300
commitd23d2a076d5fbcde43d7c176f1b27d63b39ea27b (patch)
tree0300605e476a0ce5a5793a05b8ca4011d0d75703
parent398049f018fa3ee31f11d16d79537e0c3349f7c3 (diff)
Amend most operation service tests to create repos through the API
This commit amends most of the operations service's test to create the test state through the API. This better matches the production scenario and allows for Praefect to create the metadata it would create in real setups. Most of the replacements are straight forward but some tests rely on working trees. As Gitaly does not support creating worktrees through the API, the worktrees are created after creating the repo through the API. TestUserCommitFiles was simplified a bit and its branch was changed as new repositories nowadays have main as their default branch.
-rw-r--r--internal/gitaly/service/operations/cherry_pick_test.go4
-rw-r--r--internal/gitaly/service/operations/commit_files_test.go38
-rw-r--r--internal/gitaly/service/operations/rebase_test.go39
-rw-r--r--internal/gitaly/service/operations/revert_test.go6
-rw-r--r--internal/gitaly/service/operations/squash_test.go7
-rw-r--r--internal/gitaly/service/operations/submodules_test.go2
-rw-r--r--internal/gitaly/service/operations/update_branches_test.go4
7 files changed, 52 insertions, 48 deletions
diff --git a/internal/gitaly/service/operations/cherry_pick_test.go b/internal/gitaly/service/operations/cherry_pick_test.go
index 95108c753..deb3a0706 100644
--- a/internal/gitaly/service/operations/cherry_pick_test.go
+++ b/internal/gitaly/service/operations/cherry_pick_test.go
@@ -33,7 +33,9 @@ func TestServer_UserCherryPick_successful(t *testing.T) {
cherryPickedCommit, err := repo.ReadCommit(ctx, "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab")
require.NoError(t, err)
- testRepoCopy, testRepoCopyPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) // read-only repo
+ testRepoCopy, testRepoCopyPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ }) // read-only repo
gittest.Exec(t, cfg, "-C", testRepoCopyPath, "branch", destinationBranch, "master")
diff --git a/internal/gitaly/service/operations/commit_files_test.go b/internal/gitaly/service/operations/commit_files_test.go
index 3c5c54129..f6f1de640 100644
--- a/internal/gitaly/service/operations/commit_files_test.go
+++ b/internal/gitaly/service/operations/commit_files_test.go
@@ -4,10 +4,8 @@ import (
"context"
"encoding/base64"
"fmt"
- "os"
"path/filepath"
"strconv"
- "strings"
"testing"
"time"
@@ -40,15 +38,7 @@ func TestUserCommitFiles(t *testing.T) {
targetRelativePath = "target-repository"
)
- // Multiple locations in the call path depend on the global configuration.
- // This creates a clean directory in the test storage. We then recreate the
- // repository there on every test run. This allows us to use deterministic
- // paths in the tests.
-
- startRepo, startRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
-
- pathToStorage := strings.TrimSuffix(startRepoPath, startRepo.RelativePath)
- repoPath := filepath.Join(pathToStorage, targetRelativePath)
+ startRepo, _ := gittest.CreateRepository(ctx, t, cfg)
type step struct {
actions []*gitalypb.UserCommitFilesRequest
@@ -877,17 +867,11 @@ func TestUserCommitFiles(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
- defer func() { require.NoError(t, os.RemoveAll(repoPath)) }()
- gittest.Exec(t, cfg, "init", "--bare", repoPath)
+ const branch = "main"
- const branch = "master"
-
- repo := &gitalypb.Repository{
- StorageName: startRepo.GetStorageName(),
- RelativePath: targetRelativePath,
- GlRepository: gittest.GlRepository,
- GlProjectPath: gittest.GlProjectPath,
- }
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ RelativePath: targetRelativePath,
+ })
for i, step := range tc.steps {
headerRequest := headerRequest(
@@ -943,7 +927,7 @@ func TestUserCommitFilesStableCommitID(t *testing.T) {
ctx, cfg, _, _, client := setupOperationsService(t, ctx)
- repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
for key, values := range testcfg.GitalyServersMetadataFromCfg(t, cfg) {
@@ -1001,7 +985,7 @@ func TestUserCommitFilesQuarantine(t *testing.T) {
ctx, cfg, _, _, client := setupOperationsService(t, ctx)
- repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
ctx = testhelper.MergeOutgoingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg))
@@ -1044,7 +1028,7 @@ func TestSuccessfulUserCommitFilesRequest(t *testing.T) {
ctx, cfg, repo, repoPath, client := setupOperationsService(t, ctx)
- newRepo, newRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ newRepo, newRepoPath := gittest.CreateRepository(ctx, t, cfg)
filePath := "héllo/wörld"
authorName := []byte("Jane Doe")
@@ -1169,7 +1153,9 @@ func TestSuccessfulUserCommitFilesRequestMove(t *testing.T) {
{content: "foo", infer: true},
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
- testRepo, testRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ testRepo, testRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
origFileContent := gittest.Exec(t, cfg, "-C", testRepoPath, "show", branchName+":"+previousFilePath)
headerRequest := headerRequest(testRepo, gittest.TestUser, branchName, commitFilesMessage, "")
@@ -1341,7 +1327,7 @@ func TestSuccessfulUserCommitFilesRequestWithSpecialCharactersInSignature(t *tes
ctx, cfg, _, _, client := setupOperationsService(t, ctx)
- repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ repoProto, _ := gittest.CreateRepository(ctx, t, cfg)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
targetBranchName := "master"
diff --git a/internal/gitaly/service/operations/rebase_test.go b/internal/gitaly/service/operations/rebase_test.go
index 1ac91dfe4..3574bda5b 100644
--- a/internal/gitaly/service/operations/rebase_test.go
+++ b/internal/gitaly/service/operations/rebase_test.go
@@ -3,6 +3,7 @@ package operations
import (
"fmt"
"io"
+ "path/filepath"
"strings"
"testing"
"time"
@@ -36,7 +37,9 @@ func TestSuccessfulUserRebaseConfirmableRequest(t *testing.T) {
repo := localrepo.NewTestRepo(t, cfg, repoProto)
- repoCopyProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repoCopyProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
branchSha := getBranchSha(t, cfg, repoPath, rebaseBranchName)
@@ -420,8 +423,9 @@ func TestAbortedUserRebaseConfirmable(t *testing.T) {
for i, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- testRepo, testRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
- testRepoCopy, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ createRepoOpts := gittest.CreateRepositoryConfig{Seed: gittest.SeedGitLabTest}
+ testRepo, testRepoPath := gittest.CreateRepository(ctx, t, cfg, createRepoOpts)
+ testRepoCopy, _ := gittest.CreateRepository(ctx, t, cfg, createRepoOpts)
branchSha := getBranchSha(t, cfg, testRepoPath, rebaseBranchName)
@@ -467,7 +471,9 @@ func TestFailedUserRebaseConfirmableDueToApplyBeingFalse(t *testing.T) {
repo := localrepo.NewTestRepo(t, cfg, repoProto)
- testRepoCopy, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ testRepoCopy, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
branchSha := getBranchSha(t, cfg, repoPath, rebaseBranchName)
@@ -506,7 +512,9 @@ func TestFailedUserRebaseConfirmableRequestDueToPreReceiveError(t *testing.T) {
ctx, cfg, repoProto, repoPath, client := setupOperationsService(t, ctx)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
- repoCopyProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repoCopyProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
branchSha := getBranchSha(t, cfg, repoPath, rebaseBranchName)
@@ -559,7 +567,9 @@ func TestFailedUserRebaseConfirmableDueToGitError(t *testing.T) {
ctx, cfg, repoProto, repoPath, client := setupOperationsService(t, ctx)
- repoCopyProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repoCopyProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
failedBranchName := "rebase-encoding-failure-trigger"
branchSha := getBranchSha(t, cfg, repoPath, failedBranchName)
@@ -590,14 +600,15 @@ func TestRebaseRequestWithDeletedFile(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- ctx, cfg, _, _, client := setupOperationsService(t, ctx)
- repoProto, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{
- WithWorktree: true,
- })
+ ctx, cfg, repoProto, repoPath, client := setupOperationsService(t, ctx)
+ gittest.AddWorktree(t, cfg, repoPath, "worktree")
+ repoPath = filepath.Join(repoPath, "worktree")
repo := localrepo.NewTestRepo(t, cfg, repoProto)
- repoCopyProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repoCopyProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
branch := "rebase-delete-test"
@@ -649,9 +660,11 @@ func TestRebaseOntoRemoteBranch(t *testing.T) {
repo := localrepo.NewTestRepo(t, cfg, repoProto)
- remoteRepo, remoteRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{
- WithWorktree: true,
+ remoteRepo, remoteRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
})
+ gittest.AddWorktree(t, cfg, remoteRepoPath, "worktree")
+ remoteRepoPath = filepath.Join(remoteRepoPath, "worktree")
localBranch := "master"
localBranchHash := getBranchSha(t, cfg, repoPath, localBranch)
diff --git a/internal/gitaly/service/operations/revert_test.go b/internal/gitaly/service/operations/revert_test.go
index 685e8947d..0305d6534 100644
--- a/internal/gitaly/service/operations/revert_test.go
+++ b/internal/gitaly/service/operations/revert_test.go
@@ -33,7 +33,9 @@ func TestServer_UserRevert_successful(t *testing.T) {
revertedCommit, err := repo.ReadCommit(ctx, "d59c60028b053793cecfb4022de34602e1a9218e")
require.NoError(t, err)
- testRepoCopy, testRepoCopyPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) // read-only repo
+ testRepoCopy, testRepoCopyPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ }) // read-only repo
gittest.Exec(t, cfg, "-C", testRepoCopyPath, "branch", destinationBranch, "master")
@@ -282,7 +284,7 @@ func TestServer_UserRevert_successfulIntoEmptyRepo(t *testing.T) {
masterHeadCommit, err := startRepo.ReadCommit(ctx, "master")
require.NoError(t, err)
- repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ repoProto, _ := gittest.CreateRepository(ctx, t, cfg)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
request := &gitalypb.UserRevertRequest{
diff --git a/internal/gitaly/service/operations/squash_test.go b/internal/gitaly/service/operations/squash_test.go
index ada77a9d3..b758ba4aa 100644
--- a/internal/gitaly/service/operations/squash_test.go
+++ b/internal/gitaly/service/operations/squash_test.go
@@ -207,11 +207,10 @@ func TestUserSquash_renames(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- ctx, cfg, _, _, client := setupOperationsService(t, ctx)
+ ctx, cfg, repoProto, repoPath, client := setupOperationsService(t, ctx)
- repoProto, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{
- WithWorktree: true,
- })
+ gittest.AddWorktree(t, cfg, repoPath, "worktree")
+ repoPath = filepath.Join(repoPath, "worktree")
repo := localrepo.NewTestRepo(t, cfg, repoProto)
diff --git a/internal/gitaly/service/operations/submodules_test.go b/internal/gitaly/service/operations/submodules_test.go
index d45c0d2aa..6c6107b6c 100644
--- a/internal/gitaly/service/operations/submodules_test.go
+++ b/internal/gitaly/service/operations/submodules_test.go
@@ -372,7 +372,7 @@ func TestFailedUserUpdateSubmoduleRequestDueToRepositoryEmpty(t *testing.T) {
ctx, cfg, _, _, client := setupOperationsService(t, ctx)
- repo, _ := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ repo, _ := gittest.CreateRepository(ctx, t, cfg)
request := &gitalypb.UserUpdateSubmoduleRequest{
Repository: repo,
diff --git a/internal/gitaly/service/operations/update_branches_test.go b/internal/gitaly/service/operations/update_branches_test.go
index e069ce8f8..1ea5701fa 100644
--- a/internal/gitaly/service/operations/update_branches_test.go
+++ b/internal/gitaly/service/operations/update_branches_test.go
@@ -173,7 +173,9 @@ func TestSuccessfulGitHooksForUserUpdateBranchRequest(t *testing.T) {
for _, hookName := range GitlabHooks {
t.Run(hookName, func(t *testing.T) {
- testRepo, testRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ testRepo, testRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
hookOutputTempPath := gittest.WriteEnvToCustomHook(t, testRepoPath, hookName)