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 18:44:55 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2022-02-02 14:24:21 +0300
commit33701a964fa9cc6939aa94571501e71b29efab76 (patch)
tree177e31bbd881c45243ac50c4ca0e7bc437099fc5
parent74e6566350c46d830160591e8560c93e06a64007 (diff)
Setup test repository via API in repository service tests
This commit sets up the test repository via API in repository service tests. This paves the way for disabling the Praefect's metadata creating hack in the tests. TestRemoveRepository_locking was updated to delete the lock after the test so the repository creation helpers can delete the created repository after the test.
-rw-r--r--internal/gitaly/service/repository/commit_graph_test.go4
-rw-r--r--internal/gitaly/service/repository/remove_test.go4
-rw-r--r--internal/gitaly/service/repository/search_files_test.go2
-rw-r--r--internal/gitaly/service/repository/testhelper_test.go13
4 files changed, 15 insertions, 8 deletions
diff --git a/internal/gitaly/service/repository/commit_graph_test.go b/internal/gitaly/service/repository/commit_graph_test.go
index 4f4d71a86..e87a7bbce 100644
--- a/internal/gitaly/service/repository/commit_graph_test.go
+++ b/internal/gitaly/service/repository/commit_graph_test.go
@@ -23,7 +23,7 @@ func TestWriteCommitGraph_withExistingCommitGraphCreatedWithDefaults(t *testing.
cfg, repo, repoPath, client := setupRepositoryService(t)
commitGraphPath := filepath.Join(repoPath, stats.CommitGraphRelPath)
- require.NoFileExists(t, commitGraphPath, "sanity check no commit graph")
+ require.NoError(t, os.RemoveAll(commitGraphPath))
chainPath := filepath.Join(repoPath, stats.CommitGraphChainRelPath)
require.NoFileExists(t, chainPath, "sanity check no commit graph chain exists")
@@ -59,7 +59,7 @@ func TestWriteCommitGraph_withExistingCommitGraphCreatedWithSplit(t *testing.T)
cfg, repo, repoPath, client := setupRepositoryService(t)
commitGraphPath := filepath.Join(repoPath, stats.CommitGraphRelPath)
- require.NoFileExists(t, commitGraphPath, "sanity check no commit graph")
+ require.NoError(t, os.RemoveAll(commitGraphPath))
chainPath := filepath.Join(repoPath, stats.CommitGraphChainRelPath)
require.NoFileExists(t, chainPath, "sanity check no commit graph chain exists")
diff --git a/internal/gitaly/service/repository/remove_test.go b/internal/gitaly/service/repository/remove_test.go
index 4a67fe7ce..39cb6aba2 100644
--- a/internal/gitaly/service/repository/remove_test.go
+++ b/internal/gitaly/service/repository/remove_test.go
@@ -58,7 +58,9 @@ func TestRemoveRepository_locking(t *testing.T) {
_, repo, repoPath, client := setupRepositoryService(t, testserver.WithDisablePraefect())
// Simulate a concurrent RPC holding the repository lock.
- require.NoError(t, os.WriteFile(repoPath+".lock", []byte{}, 0o644))
+ lockPath := repoPath + ".lock"
+ require.NoError(t, os.WriteFile(lockPath, []byte{}, 0o644))
+ defer func() { require.NoError(t, os.RemoveAll(lockPath)) }()
_, err := client.RemoveRepository(ctx, &gitalypb.RemoveRepositoryRequest{Repository: repo})
testhelper.RequireGrpcError(t, helper.ErrFailedPreconditionf("repository is already locked"), err)
diff --git a/internal/gitaly/service/repository/search_files_test.go b/internal/gitaly/service/repository/search_files_test.go
index 6fe803549..c2951d6a8 100644
--- a/internal/gitaly/service/repository/search_files_test.go
+++ b/internal/gitaly/service/repository/search_files_test.go
@@ -181,6 +181,8 @@ func TestSearchFilesByContentLargeFile(t *testing.T) {
for _, largeFile := range largeFiles {
t.Run(largeFile.filename, func(t *testing.T) {
require.NoError(t, os.WriteFile(filepath.Join(repoPath, largeFile.filename), bytes.Repeat([]byte(largeFile.line), largeFile.repeated), 0o644))
+ // By default, the worktree is detached. Checkout master so the branch advances with the commit.
+ gittest.Exec(t, cfg, "-C", repoPath, "checkout", "master")
gittest.Exec(t, cfg, "-C", repoPath, "add", ".")
gittest.Exec(t, cfg, "-C", repoPath,
"-c", fmt.Sprintf("user.name=%s", committerName),
diff --git a/internal/gitaly/service/repository/testhelper_test.go b/internal/gitaly/service/repository/testhelper_test.go
index f08121ee7..ea03e9e56 100644
--- a/internal/gitaly/service/repository/testhelper_test.go
+++ b/internal/gitaly/service/repository/testhelper_test.go
@@ -3,6 +3,7 @@ package repository
import (
"context"
"os"
+ "path/filepath"
"reflect"
"runtime"
"testing"
@@ -163,7 +164,10 @@ func runRepositoryService(t testing.TB, cfg config.Cfg, rubySrv *rubyserver.Serv
func setupRepositoryService(t testing.TB, opts ...testserver.GitalyServerOpt) (config.Cfg, *gitalypb.Repository, string, gitalypb.RepositoryServiceClient) {
cfg, client := setupRepositoryServiceWithoutRepo(t, opts...)
- repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+
+ repo, repoPath := gittest.CreateRepository(context.TODO(), t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
return cfg, repo, repoPath, client
}
@@ -180,11 +184,10 @@ func setupRepositoryServiceWithoutRepo(t testing.TB, opts ...testserver.GitalySe
}
func setupRepositoryServiceWithWorktree(t testing.TB, opts ...testserver.GitalyServerOpt) (config.Cfg, *gitalypb.Repository, string, gitalypb.RepositoryServiceClient) {
- cfg, client := setupRepositoryServiceWithoutRepo(t, opts...)
+ cfg, repo, repoPath, client := setupRepositoryService(t, opts...)
- repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{
- WithWorktree: true,
- })
+ gittest.AddWorktree(t, cfg, repoPath, "worktree")
+ repoPath = filepath.Join(repoPath, "worktree")
return cfg, repo, repoPath, client
}