diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-11-19 16:28:34 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-11-19 16:34:30 +0300 |
commit | 884210e963bfd155e99948ad1b6cb435d3abb195 (patch) | |
tree | 47935b30a243557765993cf47ff7f7f2d56e760f | |
parent | 54ce459ac59fbee61e4bf32d7d8772a458b23330 (diff) |
git: Convert to use `testhelper.NewTestRepo()`
We're about to move the test storage into the global temporary test
directory, which will make use of `testhelper.TestRepository()` not work
anymore. This commit thus refactors `internal/git/git` to use
`testhelper.NewTestRepo()` instead.
There is one non-trivial conversion in `TestRepositoryRemote_Add()`:
previously, we'd have asserted that the repo has both the newly added
remote as well as a preexisting "origin" remote. The "origin" remote
only results from the fact that we are setting up the repo as a clone
from our internal test repo and thus doesn't add any value to our tests.
As paths are now hard to figure out correctly, this commit just removes
the "origin" remote before executing tests.
-rw-r--r-- | internal/git/remote_test.go | 13 | ||||
-rw-r--r-- | internal/git/remoterepo/repository_test.go | 5 | ||||
-rw-r--r-- | internal/git/repository_suite.go | 5 | ||||
-rw-r--r-- | internal/git/repository_test.go | 35 |
4 files changed, 44 insertions, 14 deletions
diff --git a/internal/git/remote_test.go b/internal/git/remote_test.go index 2f7fda939..a50e2e49d 100644 --- a/internal/git/remote_test.go +++ b/internal/git/remote_test.go @@ -62,6 +62,11 @@ func TestRepositoryRemote_Add(t *testing.T) { repo, repoPath, cleanup := testhelper.NewTestRepo(t) defer cleanup() + _, remoteRepoPath, cleanup := testhelper.NewTestRepo(t) + defer cleanup() + + testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "remote", "remove", "origin") + ctx, cancel := testhelper.Context() defer cancel() @@ -96,14 +101,12 @@ func TestRepositoryRemote_Add(t *testing.T) { }) t.Run("fetch", func(t *testing.T) { - require.NoError(t, remote.Add(ctx, "first", testhelper.GitlabTestStoragePath()+"/gitlab-test.git", RemoteAddOpts{Fetch: true})) + require.NoError(t, remote.Add(ctx, "first", remoteRepoPath, RemoteAddOpts{Fetch: true})) remotes := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "remote", "--verbose")) require.Equal(t, - "first "+testhelper.GitlabTestStoragePath()+"/gitlab-test.git (fetch)\n"+ - "first "+testhelper.GitlabTestStoragePath()+"/gitlab-test.git (push)\n"+ - "origin "+testhelper.GitlabTestStoragePath()+"/gitlab-test.git (fetch)\n"+ - "origin "+testhelper.GitlabTestStoragePath()+"/gitlab-test.git (push)", + "first "+remoteRepoPath+" (fetch)\n"+ + "first "+remoteRepoPath+" (push)", remotes, ) latestSHA := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "rev-parse", "refs/remotes/first/master")) diff --git a/internal/git/remoterepo/repository_test.go b/internal/git/remoterepo/repository_test.go index b88a55413..15408e0d5 100644 --- a/internal/git/remoterepo/repository_test.go +++ b/internal/git/remoterepo/repository_test.go @@ -23,12 +23,15 @@ func TestRepository(t *testing.T) { ctx, err := helper.InjectGitalyServers(ctx, "default", serverSocketPath, config.Config.Auth.Token) require.NoError(t, err) + testRepo, _, cleanup := testhelper.NewTestRepo(t) + defer cleanup() + git.TestRepository(t, func(t testing.TB, pbRepo *gitalypb.Repository) git.Repository { t.Helper() r, err := New( helper.OutgoingToIncoming(ctx), - testhelper.TestRepository(), + testRepo, client.NewPool(), ) require.NoError(t, err) diff --git a/internal/git/repository_suite.go b/internal/git/repository_suite.go index 616530fb6..dc5c3a4e0 100644 --- a/internal/git/repository_suite.go +++ b/internal/git/repository_suite.go @@ -20,7 +20,10 @@ func TestRepository(t *testing.T, getRepository func(testing.TB, *gitalypb.Repos }, } { t.Run(tc.desc, func(t *testing.T) { - tc.test(t, getRepository(t, testhelper.TestRepository())) + testRepo, _, cleanup := testhelper.NewTestRepo(t) + defer cleanup() + + tc.test(t, getRepository(t, testRepo)) }) } } diff --git a/internal/git/repository_test.go b/internal/git/repository_test.go index 79af68e96..86f3f1920 100644 --- a/internal/git/repository_test.go +++ b/internal/git/repository_test.go @@ -35,7 +35,10 @@ func TestLocalRepository_ContainsRef(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - repo := NewRepository(testhelper.TestRepository()) + testRepo, _, cleanup := testhelper.NewTestRepo(t) + defer cleanup() + + repo := NewRepository(testRepo) testcases := []struct { desc string @@ -72,7 +75,10 @@ func TestLocalRepository_GetReference(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - repo := NewRepository(testhelper.TestRepository()) + testRepo, _, cleanup := testhelper.NewTestRepo(t) + defer cleanup() + + repo := NewRepository(testRepo) testcases := []struct { desc string @@ -118,7 +124,10 @@ func TestLocalRepository_GetBranch(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - repo := NewRepository(testhelper.TestRepository()) + testRepo, _, cleanup := testhelper.NewTestRepo(t) + defer cleanup() + + repo := NewRepository(testRepo) testcases := []struct { desc string @@ -164,7 +173,10 @@ func TestLocalRepository_GetReferences(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - repo := NewRepository(testhelper.TestRepository()) + testRepo, _, cleanup := testhelper.NewTestRepo(t) + defer cleanup() + + repo := NewRepository(testRepo) testcases := []struct { desc string @@ -291,7 +303,10 @@ func TestLocalRepository_ReadObject(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - repo := NewRepository(testhelper.TestRepository()) + testRepo, _, cleanup := testhelper.NewTestRepo(t) + defer cleanup() + + repo := NewRepository(testRepo) for _, tc := range []struct { desc string @@ -323,7 +338,10 @@ func TestLocalRepository_GetBranches(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - repo := NewRepository(testhelper.TestRepository()) + testRepo, _, cleanup := testhelper.NewTestRepo(t) + defer cleanup() + + repo := NewRepository(testRepo) refs, err := repo.GetBranches(ctx) require.NoError(t, err) @@ -450,12 +468,15 @@ func TestLocalRepository_FetchRemote(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() + _, remoteRepoPath, cleanup := testhelper.NewTestRepo(t) + defer cleanup() + initBareWithRemote := func(t *testing.T, remote string) (*LocalRepository, string, testhelper.Cleanup) { t.Helper() testRepo, testRepoPath, cleanup := testhelper.InitBareRepo(t) - cmd := exec.Command(command.GitPath(), "-C", testRepoPath, "remote", "add", remote, testhelper.GitlabTestStoragePath()+"/gitlab-test.git") + cmd := exec.Command(command.GitPath(), "-C", testRepoPath, "remote", "add", remote, remoteRepoPath) err := cmd.Run() if err != nil { cleanup() |