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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-07-29 15:13:10 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-08-02 09:28:12 +0300
commit8eb89f8307916382e228a14b6eb74288e60d68dc (patch)
treecd95b997910f4ebdcae6ac931f89ce89971cc9b2
parent3a74f1e7f064fa307da795dc1ea81807ff90be33 (diff)
localrepo: Trivial conversions to stop using seeded repositories
Similar as the preceding commit this converts remaining tests that use seeded repositories to stop doing so and instead write their required test data at runtime.
-rw-r--r--internal/git/localrepo/paths_test.go12
-rw-r--r--internal/git/localrepo/remote_extra_test.go27
-rw-r--r--internal/git/localrepo/remote_test.go54
-rw-r--r--internal/git/localrepo/repo_test.go4
4 files changed, 49 insertions, 48 deletions
diff --git a/internal/git/localrepo/paths_test.go b/internal/git/localrepo/paths_test.go
index cd33ec032..980b82a95 100644
--- a/internal/git/localrepo/paths_test.go
+++ b/internal/git/localrepo/paths_test.go
@@ -8,6 +8,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/quarantine"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config"
@@ -21,8 +22,10 @@ import (
)
func TestRepo_Path(t *testing.T) {
+ cfg := testcfg.Build(t)
+
t.Run("valid repository", func(t *testing.T) {
- cfg, repoProto, repoPath := testcfg.BuildWithRepo(t)
+ repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
repo := localrepo.NewTestRepo(t, cfg, repoProto)
path, err := repo.Path()
@@ -31,7 +34,7 @@ func TestRepo_Path(t *testing.T) {
})
t.Run("deleted repository", func(t *testing.T) {
- cfg, repoProto, repoPath := testcfg.BuildWithRepo(t)
+ repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
repo := localrepo.NewTestRepo(t, cfg, repoProto)
require.NoError(t, os.RemoveAll(repoPath))
@@ -41,7 +44,7 @@ func TestRepo_Path(t *testing.T) {
})
t.Run("non-git repository", func(t *testing.T) {
- cfg, repoProto, repoPath := testcfg.BuildWithRepo(t)
+ repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
repo := localrepo.NewTestRepo(t, cfg, repoProto)
// Recreate the repository as a simple empty directory to simulate
@@ -55,7 +58,8 @@ func TestRepo_Path(t *testing.T) {
}
func TestRepo_ObjectDirectoryPath(t *testing.T) {
- cfg, repoProto, repoPath := testcfg.BuildWithRepo(t)
+ cfg := testcfg.Build(t)
+ repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
locator := config.NewLocator(cfg)
ctx := testhelper.Context(t)
diff --git a/internal/git/localrepo/remote_extra_test.go b/internal/git/localrepo/remote_extra_test.go
index 634229054..dafd7e8ae 100644
--- a/internal/git/localrepo/remote_extra_test.go
+++ b/internal/git/localrepo/remote_extra_test.go
@@ -52,22 +52,17 @@ func TestRepo_FetchInternal(t *testing.T) {
))
}, testserver.WithGitCommandFactory(protocolDetectingFactory))
- remoteRepoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
-
- remoteRepo := localrepo.NewTestRepo(t, cfg, remoteRepoProto)
testcfg.BuildGitalySSH(t, cfg)
testcfg.BuildGitalyHooks(t, cfg)
- remoteOID, err := remoteRepo.ResolveRevision(ctx, git.Revision("refs/heads/master"))
- require.NoError(t, err)
-
- tagV100OID, err := remoteRepo.ResolveRevision(ctx, git.Revision("refs/tags/v1.0.0"))
- require.NoError(t, err)
-
- tagV110OID, err := remoteRepo.ResolveRevision(ctx, git.Revision("refs/tags/v1.1.0"))
- require.NoError(t, err)
+ remoteRepoProto, remoteRepoPath := gittest.CreateRepository(ctx, t, cfg)
+ remoteOID := gittest.WriteCommit(t, cfg, remoteRepoPath, gittest.WithBranch("master"))
+ tagV100OID := gittest.WriteTag(t, cfg, remoteRepoPath, "v1.0.0", remoteOID.Revision(), gittest.WriteTagConfig{
+ Message: "v1.0.0",
+ })
+ tagV110OID := gittest.WriteTag(t, cfg, remoteRepoPath, "v1.1.0", remoteOID.Revision(), gittest.WriteTagConfig{
+ Message: "v1.1.0",
+ })
t.Run("refspec with tag", func(t *testing.T) {
ctx := testhelper.MergeIncomingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg))
@@ -205,14 +200,12 @@ func TestRepo_FetchInternal(t *testing.T) {
t.Run("pruning", func(t *testing.T) {
ctx := testhelper.MergeIncomingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg))
- repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
+ repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
// Create a local reference. Given that it doesn't exist on the remote side, it
// would get pruned if we pass `--prune`.
- require.NoError(t, repo.UpdateRef(ctx, "refs/heads/prune-me", remoteOID, git.ObjectHashSHA1.ZeroOID))
+ gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("prune-me"))
// By default, refs are not pruned.
require.NoError(t, repo.FetchInternal(
diff --git a/internal/git/localrepo/remote_test.go b/internal/git/localrepo/remote_test.go
index 18b2e7ded..5e22e158d 100644
--- a/internal/git/localrepo/remote_test.go
+++ b/internal/git/localrepo/remote_test.go
@@ -30,11 +30,15 @@ func TestRepo_FetchRemote(t *testing.T) {
defer catfileCache.Stop()
locator := config.NewLocator(cfg)
+ _, remoteRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ commitID := gittest.WriteCommit(t, cfg, remoteRepoPath, gittest.WithBranch("main"))
+ tagID := gittest.WriteTag(t, cfg, remoteRepoPath, "v1.0.0", commitID.Revision(), gittest.WriteTagConfig{
+ Message: "annotated tag",
+ })
+
initBareWithRemote := func(t *testing.T, remote string) (*Repo, string) {
t.Helper()
- _, remoteRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
-
clientRepo, clientRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
cmd := gittest.NewCommand(t, cfg, "-C", clientRepoPath, "remote", "add", remote, remoteRepoPath)
@@ -74,22 +78,21 @@ func TestRepo_FetchRemote(t *testing.T) {
refs, err := repo.GetReferences(ctx)
require.NoError(t, err)
- require.Contains(t, refs, git.Reference{Name: "refs/remotes/origin/'test'", Target: "e56497bb5f03a90a51293fc6d516788730953899"})
- require.Contains(t, refs, git.Reference{Name: "refs/tags/v1.1.0", Target: "8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b"})
+ require.Contains(t, refs, git.Reference{Name: "refs/remotes/origin/main", Target: commitID.String()})
+ require.Contains(t, refs, git.Reference{Name: "refs/tags/v1.0.0", Target: tagID.String()})
- sha, err := repo.ResolveRevision(ctx, git.Revision("refs/remotes/origin/master^{commit}"))
+ fetchedCommitID, err := repo.ResolveRevision(ctx, git.Revision("refs/remotes/origin/main^{commit}"))
require.NoError(t, err, "the object from remote should exists in local after fetch done")
- require.Equal(t, git.ObjectID("1e292f8fedd741b75372e19097c76d327140c312"), sha)
+ require.Equal(t, commitID, fetchedCommitID)
require.NoFileExists(t, filepath.Join(repoPath, "FETCH_HEAD"))
})
t.Run("with env", func(t *testing.T) {
- _, sourceRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
- testRepo, testRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ testRepo, testRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
repo := New(locator, gitCmdFactory, catfileCache, testRepo)
- gittest.Exec(t, cfg, "-C", testRepoPath, "remote", "add", "source", sourceRepoPath)
+ gittest.Exec(t, cfg, "-C", testRepoPath, "remote", "add", "source", remoteRepoPath)
var stderr bytes.Buffer
require.NoError(t, repo.FetchRemote(ctx, "source", FetchOpts{Stderr: &stderr, Env: []string{"GIT_TRACE=1"}}))
@@ -97,11 +100,10 @@ func TestRepo_FetchRemote(t *testing.T) {
})
t.Run("with disabled transactions", func(t *testing.T) {
- _, sourceRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
- testRepo, testRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ testRepo, testRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
repo := New(locator, gitCmdFactory, catfileCache, testRepo)
- gittest.Exec(t, cfg, "-C", testRepoPath, "remote", "add", "source", sourceRepoPath)
+ gittest.Exec(t, cfg, "-C", testRepoPath, "remote", "add", "source", remoteRepoPath)
var stderr bytes.Buffer
require.NoError(t, repo.FetchRemote(ctx, "source", FetchOpts{
@@ -113,16 +115,16 @@ func TestRepo_FetchRemote(t *testing.T) {
})
t.Run("with globals", func(t *testing.T) {
- _, sourceRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
- testRepo, testRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ testRepo, testRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
repo := New(locator, gitCmdFactory, catfileCache, testRepo)
- gittest.Exec(t, cfg, "-C", testRepoPath, "remote", "add", "source", sourceRepoPath)
+ gittest.Exec(t, cfg, "-C", testRepoPath, "remote", "add", "source", remoteRepoPath)
require.NoError(t, repo.FetchRemote(ctx, "source", FetchOpts{}))
- gittest.Exec(t, cfg, "-C", testRepoPath, "branch", "--track", "testing-fetch-prune", "refs/remotes/source/markdown")
- gittest.Exec(t, cfg, "-C", sourceRepoPath, "branch", "-D", "markdown")
+ // Write a commit into the remote's reference namespace that doesn't exist in the
+ // remote and that would thus be pruned.
+ gittest.WriteCommit(t, cfg, testRepoPath, gittest.WithReference("refs/remotes/source/markdown"))
require.NoError(t, repo.FetchRemote(
ctx,
@@ -140,16 +142,15 @@ func TestRepo_FetchRemote(t *testing.T) {
})
t.Run("with prune", func(t *testing.T) {
- _, sourceRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
- testRepo, testRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ testRepo, testRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
repo := New(locator, gitCmdFactory, catfileCache, testRepo)
- gittest.Exec(t, cfg, "-C", testRepoPath, "remote", "add", "source", sourceRepoPath)
+ gittest.Exec(t, cfg, "-C", testRepoPath, "remote", "add", "source", remoteRepoPath)
require.NoError(t, repo.FetchRemote(ctx, "source", FetchOpts{}))
-
- gittest.Exec(t, cfg, "-C", testRepoPath, "branch", "--track", "testing-fetch-prune", "refs/remotes/source/markdown")
- gittest.Exec(t, cfg, "-C", sourceRepoPath, "branch", "-D", "markdown")
+ // Write a commit into the remote's reference namespace that doesn't exist in the
+ // remote and that would thus be pruned.
+ gittest.WriteCommit(t, cfg, testRepoPath, gittest.WithReference("refs/remotes/source/markdown"))
require.NoError(t, repo.FetchRemote(ctx, "source", FetchOpts{Prune: true}))
@@ -241,14 +242,17 @@ func captureGitSSHCommand(ctx context.Context, t testing.TB, cfg config.Cfg) (gi
func TestRepo_Push(t *testing.T) {
ctx := testhelper.Context(t)
- cfg, sourceRepoPb, _ := testcfg.BuildWithRepo(t)
+ cfg := testcfg.Build(t)
gitCmdFactory, readSSHCommand := captureGitSSHCommand(ctx, t, cfg)
catfileCache := catfile.NewCache(cfg)
t.Cleanup(catfileCache.Stop)
locator := config.NewLocator(cfg)
- sourceRepo := New(locator, gitCmdFactory, catfileCache, sourceRepoPb)
+ sourceRepoProto, sourceRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ sourceRepo := New(locator, gitCmdFactory, catfileCache, sourceRepoProto)
+ gittest.WriteCommit(t, cfg, sourceRepoPath, gittest.WithBranch("master"))
+ gittest.WriteCommit(t, cfg, sourceRepoPath, gittest.WithBranch("feature"))
setupPushRepo := func(t testing.TB) (*Repo, string, []git.ConfigPair) {
repoProto, repopath := gittest.InitRepo(t, cfg, cfg.Storages[0])
diff --git a/internal/git/localrepo/repo_test.go b/internal/git/localrepo/repo_test.go
index bdfa53ed7..26ae6336a 100644
--- a/internal/git/localrepo/repo_test.go
+++ b/internal/git/localrepo/repo_test.go
@@ -333,8 +333,8 @@ func TestRepo_StorageTempDir(t *testing.T) {
t.Cleanup(catfileCache.Stop)
locator := config.NewLocator(cfg)
- pbRepo, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
- repo := New(locator, gitCmdFactory, catfileCache, pbRepo)
+ repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ repo := New(locator, gitCmdFactory, catfileCache, repoProto)
expected, err := locator.TempDir(cfg.Storages[0].Name)
require.NoError(t, err)