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-24 13:39:34 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2022-02-01 18:16:04 +0300
commit5b271ebe02d5de76b54e08698490b0860ab56d12 (patch)
tree0a2cabe794ae966a5e6d8dd31f1e919841488e60
parent7779f09eb8bf76508b1393c697deb15711ed0721 (diff)
Refactor TestSuccessfulResolveConflictsRequestHelper to use the common setup
The other tests in the conflicts package use the same setup function to create the test service. TestSuccessfulResolveConflictsRequestHelper however uses different setup as it needs to know commit IDs before it can setup the mock hook manager. This commit refactors the test to use the common setup functions. This allows for later creating the test repository via the API.
-rw-r--r--internal/gitaly/service/conflicts/resolve_conflicts_test.go19
-rw-r--r--internal/gitaly/service/conflicts/testhelper_test.go22
2 files changed, 18 insertions, 23 deletions
diff --git a/internal/gitaly/service/conflicts/resolve_conflicts_test.go b/internal/gitaly/service/conflicts/resolve_conflicts_test.go
index 5ae4d6534..2647845b9 100644
--- a/internal/gitaly/service/conflicts/resolve_conflicts_test.go
+++ b/internal/gitaly/service/conflicts/resolve_conflicts_test.go
@@ -56,7 +56,18 @@ var (
)
func TestSuccessfulResolveConflictsRequestHelper(t *testing.T) {
- cfg, repoProto, repoPath := SetupConfigAndRepo(t, true)
+ var verifyFunc func(t testing.TB, pushOptions []string, stdin io.Reader)
+ verifyFuncProxy := func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error {
+ // We use a proxy func here as we need to provide the hookManager dependency while creating the service but we only
+ // know the commit IDs after the service is created. The proxy allows us to modify the verifyFunc after the service
+ // is already built.
+ verifyFunc(t, pushOptions, stdin)
+ return nil
+ }
+
+ hookManager := hook.NewMockManager(t, verifyFuncProxy, verifyFuncProxy, hook.NopUpdate, hook.NopReferenceTransaction)
+ cfg, repoProto, repoPath, client := SetupConflictsService(t, true, hookManager)
+
repo := localrepo.NewTestRepo(t, cfg, repoProto)
ctx := testhelper.Context(t)
@@ -126,19 +137,15 @@ func TestSuccessfulResolveConflictsRequestHelper(t *testing.T) {
theirCommitOID = commitConflict(theirCommitOID, targetBranch, "content-2")
hookCount := 0
- verifyFunc := func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error {
+ verifyFunc = func(t testing.TB, pushOptions []string, stdin io.Reader) {
changes, err := io.ReadAll(stdin)
require.NoError(t, err)
pattern := fmt.Sprintf("%s .* refs/heads/%s\n", ourCommitOID, sourceBranch)
require.Regexp(t, regexp.MustCompile(pattern), string(changes))
require.Empty(t, pushOptions)
hookCount++
- return nil
}
- hookManager := hook.NewMockManager(t, verifyFunc, verifyFunc, hook.NopUpdate, hook.NopReferenceTransaction)
- client := SetupConflictsServiceWithConfig(t, &cfg, hookManager)
-
mdGS := testcfg.GitalyServersMetadataFromCfg(t, cfg)
mdFF, _ := metadata.FromOutgoingContext(ctx)
ctx = metadata.NewOutgoingContext(ctx, metadata.Join(mdGS, mdFF))
diff --git a/internal/gitaly/service/conflicts/testhelper_test.go b/internal/gitaly/service/conflicts/testhelper_test.go
index 8280cfde3..73efc3fb0 100644
--- a/internal/gitaly/service/conflicts/testhelper_test.go
+++ b/internal/gitaly/service/conflicts/testhelper_test.go
@@ -22,32 +22,20 @@ func TestMain(m *testing.M) {
testhelper.Run(m)
}
-func SetupConfigAndRepo(t testing.TB, bare bool) (config.Cfg, *gitalypb.Repository, string) {
+func SetupConflictsService(t testing.TB, bare bool, hookManager hook.Manager) (config.Cfg, *gitalypb.Repository, string, gitalypb.ConflictsServiceClient) {
cfg := testcfg.Build(t)
testcfg.BuildGitalyGit2Go(t, cfg)
- repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{
- WithWorktree: !bare,
- })
-
- return cfg, repo, repoPath
-}
-
-func SetupConflictsServiceWithConfig(t testing.TB, cfg *config.Cfg, hookManager hook.Manager) gitalypb.ConflictsServiceClient {
- serverSocketPath := runConflictsServer(t, *cfg, hookManager)
+ serverSocketPath := runConflictsServer(t, cfg, hookManager)
cfg.SocketPath = serverSocketPath
client, conn := NewConflictsClient(t, serverSocketPath)
t.Cleanup(func() { conn.Close() })
- return client
-}
-
-func SetupConflictsService(t testing.TB, bare bool, hookManager hook.Manager) (config.Cfg, *gitalypb.Repository, string, gitalypb.ConflictsServiceClient) {
- cfg, repo, repoPath := SetupConfigAndRepo(t, bare)
-
- client := SetupConflictsServiceWithConfig(t, &cfg, hookManager)
+ repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{
+ WithWorktree: !bare,
+ })
return cfg, repo, repoPath, client
}