diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2022-01-20 19:02:44 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2022-02-02 14:24:22 +0300 |
commit | b9b42f5a824c664a6eddb551221904b6602488fd (patch) | |
tree | 7141ae3fe35b41c284c1c559f9d5e7ce65b93c15 | |
parent | f9509ea854c0654a65f6cba4e0fdcf71bc25f573 (diff) |
Create repository via API in FetchRemote tests
This commits converts FetchRemote to also create repositories via
API. The tests were somewhat simplified by removing a method to copy
the test repository and instead initiate another copy of the test repo
using the existing helpers. As TestFetchRemote_sshCommand is overriding
the git command, it's not possible to create repositories via the API.
Thus, the test is skipped when Praefect is enabled.
-rw-r--r-- | internal/gitaly/service/repository/fetch_remote_test.go | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/internal/gitaly/service/repository/fetch_remote_test.go b/internal/gitaly/service/repository/fetch_remote_test.go index 368dd4e05..7fc2cec45 100644 --- a/internal/gitaly/service/repository/fetch_remote_test.go +++ b/internal/gitaly/service/repository/fetch_remote_test.go @@ -30,26 +30,15 @@ import ( "google.golang.org/grpc/status" ) -func copyRepo(t *testing.T, cfg config.Cfg, repo *gitalypb.Repository, repoPath string) *gitalypb.Repository { - cloneRepo := &gitalypb.Repository{ - StorageName: repo.GetStorageName(), - RelativePath: filepath.Join(filepath.Dir(repo.GetRelativePath()), "fetch-remote-clone.git"), - } - - clonePath := filepath.Join(filepath.Dir(repoPath), "fetch-remote-clone.git") - require.NoError(t, os.RemoveAll(clonePath)) - - gittest.Exec(t, cfg, "clone", "--bare", repoPath, clonePath) - - return cloneRepo -} - func TestFetchRemoteSuccess(t *testing.T) { t.Parallel() - cfg, repo, repoPath, client := setupRepositoryService(t) + + cfg, _, repoPath, client := setupRepositoryService(t) ctx := testhelper.Context(t) - cloneRepo := copyRepo(t, cfg, repo, repoPath) + cloneRepo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + Seed: gittest.SeedGitLabTest, + }) // Ensure there's a new tag to fetch gittest.WriteTag(t, cfg, repoPath, "testtag", "master") @@ -71,6 +60,8 @@ func TestFetchRemoteSuccess(t *testing.T) { } func TestFetchRemote_sshCommand(t *testing.T) { + testhelper.SkipWithPraefect(t, "It's not possible to create repositories through the API with the git command overwritten by the script.") + t.Parallel() cfg, repo, _ := testcfg.BuildWithRepo(t) @@ -146,9 +137,11 @@ func TestFetchRemote_withDefaultRefmaps(t *testing.T) { sourceRepo := localrepo.NewTestRepo(t, cfg, sourceRepoProto) - targetRepoProto := copyRepo(t, cfg, sourceRepoProto, sourceRepoPath) - targetRepo := localrepo.NewTestRepo(t, cfg, targetRepoProto) ctx := testhelper.Context(t) + targetRepoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + Seed: gittest.SeedGitLabTest, + }) + targetRepo := localrepo.NewTestRepo(t, cfg, targetRepoProto) port, stopGitServer := gittest.HTTPServer(ctx, t, gitCmdFactory, sourceRepoPath, nil) defer func() { require.NoError(t, stopGitServer()) }() @@ -176,7 +169,7 @@ func TestFetchRemote_withDefaultRefmaps(t *testing.T) { func TestFetchRemote_transaction(t *testing.T) { t.Parallel() - sourceCfg, _, sourceRepoPath := testcfg.BuildWithRepo(t) + sourceCfg := testcfg.Build(t) txManager := transaction.NewTrackingManager() addr := testserver.RunGitalyServer(t, sourceCfg, nil, func(srv *grpc.Server, deps *service.Dependencies) { @@ -191,12 +184,20 @@ func TestFetchRemote_transaction(t *testing.T) { deps.GetGit2goExecutor(), )) }, testserver.WithTransactionManager(txManager)) + sourceCfg.SocketPath = addr client := newRepositoryClient(t, sourceCfg, addr) + ctx := testhelper.Context(t) + _, sourceRepoPath := gittest.CreateRepository(ctx, t, sourceCfg, gittest.CreateRepositoryConfig{ + RelativePath: t.Name(), + Seed: gittest.SeedGitLabTest, + }) + // Reset the manager as creating the repository casts some votes. + txManager.Reset() + targetCfg, targetRepoProto, targetRepoPath := testcfg.BuildWithRepo(t) targetGitCmdFactory := gittest.NewCommandFactory(t, targetCfg) - ctx := testhelper.Context(t) port, stopGitServer := gittest.HTTPServer(ctx, t, targetGitCmdFactory, targetRepoPath, nil) defer func() { require.NoError(t, stopGitServer()) }() @@ -220,7 +221,7 @@ func TestFetchRemote_transaction(t *testing.T) { func TestFetchRemote_prune(t *testing.T) { t.Parallel() - cfg, sourceRepo, sourceRepoPath, client := setupRepositoryService(t) + cfg, _, sourceRepoPath, client := setupRepositoryService(t) gitCmdFactory := gittest.NewCommandFactory(t, cfg) ctx := testhelper.Context(t) @@ -273,7 +274,9 @@ func TestFetchRemote_prune(t *testing.T) { }, } { t.Run(tc.desc, func(t *testing.T) { - targetRepoProto := copyRepo(t, cfg, sourceRepo, sourceRepoPath) + targetRepoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + Seed: gittest.SeedGitLabTest, + }) targetRepo := localrepo.NewTestRepo(t, cfg, targetRepoProto) require.NoError(t, targetRepo.UpdateRef(ctx, tc.ref, "refs/heads/master", "")) @@ -398,7 +401,9 @@ func TestFetchRemote_force(t *testing.T) { }, } { t.Run(tc.desc, func(t *testing.T) { - targetRepoProto := copyRepo(t, cfg, sourceRepoProto, sourceRepoPath) + targetRepoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + Seed: gittest.SeedGitLabTest, + }) targetRepo := localrepo.NewTestRepo(t, cfg, targetRepoProto) @@ -592,7 +597,9 @@ func TestFetchRemoteOverHTTP(t *testing.T) { for _, tc := range testCases { t.Run(tc.description, func(t *testing.T) { - forkedRepo, forkedRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + forkedRepo, forkedRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + Seed: gittest.SeedGitLabTest, + }) s, remoteURL := remoteHTTPServer(t, "my-repo", tc.httpToken) defer s.Close() @@ -629,7 +636,9 @@ func TestFetchRemoteWithPath(t *testing.T) { cfg, _, sourceRepoPath, client := setupRepositoryService(t) ctx := testhelper.Context(t) - mirrorRepo, mirrorRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + mirrorRepo, mirrorRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + Seed: gittest.SeedGitLabTest, + }) _, err := client.FetchRemote(ctx, &gitalypb.FetchRemoteRequest{ Repository: mirrorRepo, |