diff options
author | Pavlo Strokov <pstrokov@gitlab.com> | 2021-03-23 11:12:05 +0300 |
---|---|---|
committer | Pavlo Strokov <pstrokov@gitlab.com> | 2021-03-23 11:12:05 +0300 |
commit | f41e294dfc53b3c9a396bd881e457d64db9d7494 (patch) | |
tree | e7ed3a889ee795fdf45ece5eeddedd1b7b05d66c | |
parent | e4300c99e075d118e4a7bebeef8ee4e8672c3591 (diff) | |
parent | ab9ad3e40251bb014f6cb310b8a1911f97a7005b (diff) |
Merge branch 'ps-rm-config-conflicts' into 'master'
Removal of config.Config from conflicts package
See merge request gitlab-org/gitaly!3260
-rw-r--r-- | internal/gitaly/service/conflicts/list_conflict_files_test.go | 77 | ||||
-rw-r--r-- | internal/gitaly/service/conflicts/resolve_conflicts_test.go | 137 | ||||
-rw-r--r-- | internal/gitaly/service/conflicts/testhelper_test.go | 60 | ||||
-rw-r--r-- | internal/testhelper/configure.go | 19 |
4 files changed, 136 insertions, 157 deletions
diff --git a/internal/gitaly/service/conflicts/list_conflict_files_test.go b/internal/gitaly/service/conflicts/list_conflict_files_test.go index e7a14b116..c8dde14b1 100644 --- a/internal/gitaly/service/conflicts/list_conflict_files_test.go +++ b/internal/gitaly/service/conflicts/list_conflict_files_test.go @@ -10,7 +10,6 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/git" - "gitlab.com/gitlab-org/gitaly/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/internal/git/localrepo" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" @@ -27,14 +26,7 @@ func TestSuccessfulListConflictFilesRequest(t *testing.T) { ctx, cleanup := testhelper.Context() defer cleanup() - serverSocketPath, stop := runConflictsServer(t) - defer stop() - - client, conn := NewConflictsClient(t, serverSocketPath) - defer conn.Close() - - testRepo, _, cleanupFn := gittest.CloneRepo(t) - defer cleanupFn() + _, repo, _, client := SetupConflictsService(t, false) ourCommitOid := "1a35b5a77cf6af7edf6703f88e82f6aff613666f" theirCommitOid := "8309e68585b28d61eb85b7e2834849dda6bf1733" @@ -59,7 +51,7 @@ end ` request := &gitalypb.ListConflictFilesRequest{ - Repository: testRepo, + Repository: repo, OurCommitOid: ourCommitOid, TheirCommitOid: theirCommitOid, } @@ -101,20 +93,13 @@ func TestSuccessfulListConflictFilesRequestWithAncestor(t *testing.T) { ctx, cleanup := testhelper.Context() defer cleanup() - serverSocketPath, stop := runConflictsServer(t) - defer stop() - - client, conn := NewConflictsClient(t, serverSocketPath) - defer conn.Close() - - testRepo, _, cleanupFn := gittest.CloneRepo(t) - defer cleanupFn() + _, repo, _, client := SetupConflictsService(t, true) ourCommitOid := "824be604a34828eb682305f0d963056cfac87b2d" theirCommitOid := "1450cd639e0bc6721eb02800169e464f212cde06" request := &gitalypb.ListConflictFilesRequest{ - Repository: testRepo, + Repository: repo, OurCommitOid: ourCommitOid, TheirCommitOid: theirCommitOid, } @@ -155,21 +140,14 @@ func TestListConflictFilesHugeDiff(t *testing.T) { ctx, cleanup := testhelper.Context() defer cleanup() - serverSocketPath, stop := runConflictsServer(t) - defer stop() - - client, conn := NewConflictsClient(t, serverSocketPath) - defer conn.Close() - - repo, repoPath, cleanupFn := gittest.CloneRepoWithWorktree(t) - defer cleanupFn() + cfg, repo, repoPath, client := SetupConflictsService(t, false) - our := buildCommit(t, ctx, repo, repoPath, map[string][]byte{ + our := buildCommit(t, ctx, cfg, repo, repoPath, map[string][]byte{ "a": bytes.Repeat([]byte("a\n"), 128*1024), "b": bytes.Repeat([]byte("b\n"), 128*1024), }) - their := buildCommit(t, ctx, repo, repoPath, map[string][]byte{ + their := buildCommit(t, ctx, cfg, repo, repoPath, map[string][]byte{ "a": bytes.Repeat([]byte("x\n"), 128*1024), "b": bytes.Repeat([]byte("y\n"), 128*1024), }) @@ -181,9 +159,7 @@ func TestListConflictFilesHugeDiff(t *testing.T) { } c, err := client.ListConflictFiles(ctx, request) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) receivedFiles := getConflictFiles(t, c) require.Len(t, receivedFiles, 2) @@ -202,7 +178,9 @@ func TestListConflictFilesHugeDiff(t *testing.T) { }, receivedFiles[1].header) } -func buildCommit(t *testing.T, ctx context.Context, repo *gitalypb.Repository, repoPath string, files map[string][]byte) string { +func buildCommit(t *testing.T, ctx context.Context, cfg config.Cfg, repo *gitalypb.Repository, repoPath string, files map[string][]byte) string { + t.Helper() + for file, contents := range files { filePath := filepath.Join(repoPath, file) require.NoError(t, ioutil.WriteFile(filePath, contents, 0666)) @@ -211,7 +189,7 @@ func buildCommit(t *testing.T, ctx context.Context, repo *gitalypb.Repository, r testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "commit", "-m", "message") - oid, err := localrepo.New(git.NewExecCommandFactory(config.Config), repo, config.Config).ResolveRevision(ctx, git.Revision("HEAD")) + oid, err := localrepo.New(git.NewExecCommandFactory(cfg), repo, cfg).ResolveRevision(ctx, git.Revision("HEAD")) require.NoError(t, err) testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "reset", "--hard", "HEAD~") @@ -223,14 +201,7 @@ func TestListConflictFilesFailedPrecondition(t *testing.T) { ctx, cleanup := testhelper.Context() defer cleanup() - serverSocketPath, stop := runConflictsServer(t) - defer stop() - - client, conn := NewConflictsClient(t, serverSocketPath) - defer conn.Close() - - testRepo, _, cleanupFn := gittest.CloneRepo(t) - defer cleanupFn() + _, repo, _, client := SetupConflictsService(t, true) testCases := []struct { desc string @@ -269,7 +240,7 @@ func TestListConflictFilesFailedPrecondition(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { request := &gitalypb.ListConflictFilesRequest{ - Repository: testRepo, + Repository: repo, OurCommitOid: tc.ourCommitOid, TheirCommitOid: tc.theirCommitOid, } @@ -288,14 +259,7 @@ func TestFailedListConflictFilesRequestDueToValidation(t *testing.T) { ctx, cleanup := testhelper.Context() defer cleanup() - serverSocketPath, stop := runConflictsServer(t) - defer stop() - - client, conn := NewConflictsClient(t, serverSocketPath) - defer conn.Close() - - testRepo, _, cleanupFn := gittest.CloneRepo(t) - defer cleanupFn() + _, repo, _, client := SetupConflictsService(t, true) ourCommitOid := "0b4bc9a49b562e85de7cc9e834518ea6828729b9" theirCommitOid := "bb5206fee213d983da88c47f9cf4cc6caf9c66dc" @@ -317,7 +281,7 @@ func TestFailedListConflictFilesRequestDueToValidation(t *testing.T) { { desc: "empty OurCommitId field", request: &gitalypb.ListConflictFilesRequest{ - Repository: testRepo, + Repository: repo, OurCommitOid: "", TheirCommitOid: theirCommitOid, }, @@ -326,7 +290,7 @@ func TestFailedListConflictFilesRequestDueToValidation(t *testing.T) { { desc: "empty TheirCommitId field", request: &gitalypb.ListConflictFilesRequest{ - Repository: testRepo, + Repository: repo, OurCommitOid: ourCommitOid, TheirCommitOid: "", }, @@ -343,16 +307,17 @@ func TestFailedListConflictFilesRequestDueToValidation(t *testing.T) { } func getConflictFiles(t *testing.T, c gitalypb.ConflictsService_ListConflictFilesClient) []*conflictFile { - files := []*conflictFile{} + t.Helper() + + var files []*conflictFile var currentFile *conflictFile for { r, err := c.Recv() if err == io.EOF { break - } else if err != nil { - t.Fatal(err) } + require.NoError(t, err) for _, file := range r.GetFiles() { // If there's a header this is the beginning of a new file diff --git a/internal/gitaly/service/conflicts/resolve_conflicts_test.go b/internal/gitaly/service/conflicts/resolve_conflicts_test.go index bee92f864..533dd498c 100644 --- a/internal/gitaly/service/conflicts/resolve_conflicts_test.go +++ b/internal/gitaly/service/conflicts/resolve_conflicts_test.go @@ -11,13 +11,13 @@ import ( "github.com/golang/protobuf/ptypes/timestamp" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/git" - "gitlab.com/gitlab-org/gitaly/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/internal/git/localrepo" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/conflicts" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/internal/testhelper" - "gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver" + "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" @@ -51,29 +51,36 @@ var ( } ) -func TestSuccessfulResolveConflictsRequest(t *testing.T) { +func TestWithRubyServer(t *testing.T) { + cfg := testcfg.Build(t) + + rubySrv := rubyserver.New(cfg) + require.NoError(t, rubySrv.Start()) + t.Cleanup(rubySrv.Stop) + + t.Run("testSuccessfulResolveConflictsRequest", func(t *testing.T) { testSuccessfulResolveConflictsRequest(t, cfg, rubySrv) }) + t.Run("testResolveConflictsStableID", func(t *testing.T) { testResolveConflictsStableID(t, cfg, rubySrv) }) + t.Run("testFailedResolveConflictsRequestDueToResolutionError", func(t *testing.T) { testFailedResolveConflictsRequestDueToResolutionError(t, cfg, rubySrv) }) + t.Run("testFailedResolveConflictsRequestDueToValidation", func(t *testing.T) { testFailedResolveConflictsRequestDueToValidation(t, cfg, rubySrv) }) +} + +func testSuccessfulResolveConflictsRequest(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) { testhelper.NewFeatureSets([]featureflag.FeatureFlag{ featureflag.GoResolveConflicts, }).Run(t, func(t *testing.T, ctx context.Context) { - testSuccessfulResolveConflictsRequest(t, ctx) + testSuccessfulResolveConflictsRequestFeatured(t, ctx, cfg, rubySrv) }) } -func testSuccessfulResolveConflictsRequest(t *testing.T, ctx context.Context) { - serverSocketPath, clean := runFullServer(t) - defer clean() +func testSuccessfulResolveConflictsRequestFeatured(t *testing.T, ctx context.Context, cfg config.Cfg, rubySrv *rubyserver.Server) { + cfg, repoProto, repoPath, client := conflicts.SetupConflictsServiceWithRuby(t, cfg, rubySrv, true) - client, conn := conflicts.NewConflictsClient(t, serverSocketPath) - defer conn.Close() - - testRepo, testRepoPath, cleanupFn := gittest.CloneRepo(t) - defer cleanupFn() - repo := localrepo.New(git.NewExecCommandFactory(config.Config), testRepo, config.Config) + repo := localrepo.New(git.NewExecCommandFactory(cfg), repoProto, cfg) ctxOuter, cancel := testhelper.Context() defer cancel() - mdGS := testhelper.GitalyServersMetadata(t, serverSocketPath) + mdGS := testhelper.GitalyServersMetadata(t, cfg.SocketPath) mdFF, _ := metadata.FromOutgoingContext(ctx) ctx = metadata.NewOutgoingContext(ctx, metadata.Join(mdGS, mdFF)) @@ -116,26 +123,26 @@ func testSuccessfulResolveConflictsRequest(t *testing.T, ctx context.Context) { // introduce a conflict that exists on both branches, but not the // ancestor commitConflict := func(parentCommitID, branch, blob string) string { - blobID, err := localrepo.New(git.NewExecCommandFactory(config.Config), testRepo, config.Config).WriteBlob(ctx, "", strings.NewReader(blob)) + blobID, err := repo.WriteBlob(ctx, "", strings.NewReader(blob)) require.NoError(t, err) - testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "read-tree", branch) + testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "read-tree", branch) testhelper.MustRunCommand(t, nil, - "git", "-C", testRepoPath, + "git", "-C", repoPath, "update-index", "--add", "--cacheinfo", "100644", blobID.String(), missingAncestorPath, ) treeID := bytes.TrimSpace( testhelper.MustRunCommand(t, nil, - "git", "-C", testRepoPath, "write-tree", + "git", "-C", repoPath, "write-tree", ), ) commitID := bytes.TrimSpace( testhelper.MustRunCommand(t, nil, - "git", "-C", testRepoPath, + "git", "-C", repoPath, "commit-tree", string(treeID), "-p", parentCommitID, ), ) testhelper.MustRunCommand(t, nil, - "git", "-C", testRepoPath, "update-ref", "refs/heads/"+branch, string(commitID)) + "git", "-C", repoPath, "update-ref", "refs/heads/"+branch, string(commitID)) return string(commitID) } @@ -150,8 +157,8 @@ func testSuccessfulResolveConflictsRequest(t *testing.T, ctx context.Context) { headerRequest := &gitalypb.ResolveConflictsRequest{ ResolveConflictsRequestPayload: &gitalypb.ResolveConflictsRequest_Header{ Header: &gitalypb.ResolveConflictsRequestHeader{ - Repository: testRepo, - TargetRepository: testRepo, + Repository: repoProto, + TargetRepository: repoProto, CommitMessage: []byte(conflictResolutionCommitMessage), OurCommitOid: ourCommitOID, TheirCommitOid: theirCommitOID, @@ -191,26 +198,22 @@ func testSuccessfulResolveConflictsRequest(t *testing.T, ctx context.Context) { require.Equal(t, string(headCommit.Subject), conflictResolutionCommitMessage) } -func TestResolveConflicts_stableID(t *testing.T) { +func testResolveConflictsStableID(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) { + testhelper.ConfigureGitalyHooksBin(t, cfg) + testhelper.NewFeatureSets([]featureflag.FeatureFlag{ featureflag.GoResolveConflicts, }).Run(t, func(t *testing.T, ctx context.Context) { - testResolveConflictsStableID(t, ctx) + testResolveConflictsStableIDFeatured(t, ctx, cfg, rubySrv) }) } -func testResolveConflictsStableID(t *testing.T, ctx context.Context) { - serverSocketPath, clean := runFullServer(t) - defer clean() +func testResolveConflictsStableIDFeatured(t *testing.T, ctx context.Context, cfg config.Cfg, rubySrv *rubyserver.Server) { + cfg, repoProto, _, client := conflicts.SetupConflictsServiceWithRuby(t, cfg, rubySrv, true) - client, conn := conflicts.NewConflictsClient(t, serverSocketPath) - defer conn.Close() + repo := localrepo.New(git.NewExecCommandFactory(cfg), repoProto, cfg) - repoProto, _, cleanupFn := gittest.CloneRepo(t) - defer cleanupFn() - repo := localrepo.New(git.NewExecCommandFactory(config.Config), repoProto, config.Config) - - md := testhelper.GitalyServersMetadata(t, serverSocketPath) + md := testhelper.GitalyServersMetadata(t, cfg.SocketPath) ctx = testhelper.MergeOutgoingMetadata(ctx, md) stream, err := client.ResolveConflicts(ctx) @@ -271,25 +274,18 @@ func testResolveConflictsStableID(t *testing.T, ctx context.Context) { }, resolvedCommit) } -func TestFailedResolveConflictsRequestDueToResolutionError(t *testing.T) { +func testFailedResolveConflictsRequestDueToResolutionError(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) { testhelper.NewFeatureSets([]featureflag.FeatureFlag{ featureflag.GoResolveConflicts, }).Run(t, func(t *testing.T, ctx context.Context) { - testFailedResolveConflictsRequestDueToResolutionError(t, ctx) + testFailedResolveConflictsRequestDueToResolutionErrorFeatured(t, ctx, cfg, rubySrv) }) } -func testFailedResolveConflictsRequestDueToResolutionError(t *testing.T, ctx context.Context) { - serverSocketPath, clean := runFullServer(t) - defer clean() - - client, conn := conflicts.NewConflictsClient(t, serverSocketPath) - defer conn.Close() +func testFailedResolveConflictsRequestDueToResolutionErrorFeatured(t *testing.T, ctx context.Context, cfg config.Cfg, rubySrv *rubyserver.Server) { + cfg, repo, _, client := conflicts.SetupConflictsServiceWithRuby(t, cfg, rubySrv, true) - testRepo, _, cleanupFn := gittest.CloneRepo(t) - defer cleanupFn() - - mdGS := testhelper.GitalyServersMetadata(t, serverSocketPath) + mdGS := testhelper.GitalyServersMetadata(t, cfg.SocketPath) mdFF, _ := metadata.FromOutgoingContext(ctx) ctx = metadata.NewOutgoingContext(ctx, metadata.Join(mdGS, mdFF)) @@ -313,8 +309,8 @@ func testFailedResolveConflictsRequestDueToResolutionError(t *testing.T, ctx con headerRequest := &gitalypb.ResolveConflictsRequest{ ResolveConflictsRequestPayload: &gitalypb.ResolveConflictsRequest_Header{ Header: &gitalypb.ResolveConflictsRequestHeader{ - Repository: testRepo, - TargetRepository: testRepo, + Repository: repo, + TargetRepository: repo, CommitMessage: []byte(conflictResolutionCommitMessage), OurCommitOid: "1450cd639e0bc6721eb02800169e464f212cde06", TheirCommitOid: "824be604a34828eb682305f0d963056cfac87b2d", @@ -340,25 +336,18 @@ func testFailedResolveConflictsRequestDueToResolutionError(t *testing.T, ctx con require.Equal(t, r.GetResolutionError(), "Missing resolution for section ID: 6eb14e00385d2fb284765eb1cd8d420d33d63fc9_21_21") } -func TestFailedResolveConflictsRequestDueToValidation(t *testing.T) { +func testFailedResolveConflictsRequestDueToValidation(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) { testhelper.NewFeatureSets([]featureflag.FeatureFlag{ featureflag.GoResolveConflicts, }).Run(t, func(t *testing.T, ctx context.Context) { - testFailedResolveConflictsRequestDueToValidation(t, ctx) + testFailedResolveConflictsRequestDueToValidationFeatured(t, ctx, cfg, rubySrv) }) } -func testFailedResolveConflictsRequestDueToValidation(t *testing.T, ctx context.Context) { - serverSocketPath, clean := runFullServer(t) - defer clean() - - client, conn := conflicts.NewConflictsClient(t, serverSocketPath) - defer conn.Close() +func testFailedResolveConflictsRequestDueToValidationFeatured(t *testing.T, ctx context.Context, cfg config.Cfg, rubySrv *rubyserver.Server) { + cfg, repo, _, client := conflicts.SetupConflictsServiceWithRuby(t, cfg, rubySrv, true) - testRepo, _, cleanupFn := gittest.CloneRepo(t) - defer cleanupFn() - - mdGS := testhelper.GitalyServersMetadata(t, serverSocketPath) + mdGS := testhelper.GitalyServersMetadata(t, cfg.SocketPath) ourCommitOid := "1450cd639e0bc6721eb02800169e464f212cde06" theirCommitOid := "824be604a34828eb682305f0d963056cfac87b2d" commitMsg := []byte(conflictResolutionCommitMessage) @@ -375,7 +364,7 @@ func testFailedResolveConflictsRequestDueToValidation(t *testing.T, ctx context. header: &gitalypb.ResolveConflictsRequestHeader{ Repository: nil, OurCommitOid: ourCommitOid, - TargetRepository: testRepo, + TargetRepository: repo, TheirCommitOid: theirCommitOid, CommitMessage: commitMsg, SourceBranch: sourceBranch, @@ -386,7 +375,7 @@ func testFailedResolveConflictsRequestDueToValidation(t *testing.T, ctx context. { desc: "empty target repo", header: &gitalypb.ResolveConflictsRequestHeader{ - Repository: testRepo, + Repository: repo, OurCommitOid: ourCommitOid, TargetRepository: nil, TheirCommitOid: theirCommitOid, @@ -399,9 +388,9 @@ func testFailedResolveConflictsRequestDueToValidation(t *testing.T, ctx context. { desc: "empty OurCommitId repo", header: &gitalypb.ResolveConflictsRequestHeader{ - Repository: testRepo, + Repository: repo, OurCommitOid: "", - TargetRepository: testRepo, + TargetRepository: repo, TheirCommitOid: theirCommitOid, CommitMessage: commitMsg, SourceBranch: sourceBranch, @@ -412,9 +401,9 @@ func testFailedResolveConflictsRequestDueToValidation(t *testing.T, ctx context. { desc: "empty TheirCommitId repo", header: &gitalypb.ResolveConflictsRequestHeader{ - Repository: testRepo, + Repository: repo, OurCommitOid: ourCommitOid, - TargetRepository: testRepo, + TargetRepository: repo, TheirCommitOid: "", CommitMessage: commitMsg, SourceBranch: sourceBranch, @@ -425,9 +414,9 @@ func testFailedResolveConflictsRequestDueToValidation(t *testing.T, ctx context. { desc: "empty CommitMessage repo", header: &gitalypb.ResolveConflictsRequestHeader{ - Repository: testRepo, + Repository: repo, OurCommitOid: ourCommitOid, - TargetRepository: testRepo, + TargetRepository: repo, TheirCommitOid: theirCommitOid, CommitMessage: nil, SourceBranch: sourceBranch, @@ -438,9 +427,9 @@ func testFailedResolveConflictsRequestDueToValidation(t *testing.T, ctx context. { desc: "empty SourceBranch repo", header: &gitalypb.ResolveConflictsRequestHeader{ - Repository: testRepo, + Repository: repo, OurCommitOid: ourCommitOid, - TargetRepository: testRepo, + TargetRepository: repo, TheirCommitOid: theirCommitOid, CommitMessage: commitMsg, SourceBranch: nil, @@ -451,9 +440,9 @@ func testFailedResolveConflictsRequestDueToValidation(t *testing.T, ctx context. { desc: "empty TargetBranch repo", header: &gitalypb.ResolveConflictsRequestHeader{ - Repository: testRepo, + Repository: repo, OurCommitOid: ourCommitOid, - TargetRepository: testRepo, + TargetRepository: repo, TheirCommitOid: theirCommitOid, CommitMessage: commitMsg, SourceBranch: sourceBranch, @@ -483,7 +472,3 @@ func testFailedResolveConflictsRequestDueToValidation(t *testing.T, ctx context. }) } } - -func runFullServer(t *testing.T) (string, func()) { - return testserver.RunGitalyServer(t, config.Config, conflicts.RubyServer) -} diff --git a/internal/gitaly/service/conflicts/testhelper_test.go b/internal/gitaly/service/conflicts/testhelper_test.go index 6e92d94d2..c7c31961b 100644 --- a/internal/gitaly/service/conflicts/testhelper_test.go +++ b/internal/gitaly/service/conflicts/testhelper_test.go @@ -8,17 +8,18 @@ import ( log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/internal/git" + "gitlab.com/gitlab-org/gitaly/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/internal/git/hooks" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/repository" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc" - "google.golang.org/grpc/reflection" ) -var RubyServer *rubyserver.Server - func TestMain(m *testing.M) { os.Exit(testMain(m)) } @@ -28,7 +29,6 @@ func testMain(m *testing.M) int { cleanup := testhelper.Configure() defer cleanup() - testhelper.ConfigureGitalyGit2Go(config.Config.BinDir) tempDir, err := ioutil.TempDir("", "gitaly") if err != nil { @@ -37,32 +37,56 @@ func testMain(m *testing.M) int { } defer os.RemoveAll(tempDir) - // dir of the BinDir is a temp folder - hooks.Override = filepath.Join(filepath.Dir(config.Config.BinDir), "/hooks") + defer func(old string) { hooks.Override = old }(hooks.Override) + hooks.Override = filepath.Join(tempDir, "hooks") - RubyServer = rubyserver.New(config.Config) - if err := RubyServer.Start(); err != nil { - log.Error(err) - return 1 + return m.Run() +} + +func SetupConflictsServiceWithRuby(t testing.TB, cfg config.Cfg, rubySrv *rubyserver.Server, bare bool) (config.Cfg, *gitalypb.Repository, string, gitalypb.ConflictsServiceClient) { + testhelper.ConfigureGitalyGit2GoBin(t, cfg) + + var repo *gitalypb.Repository + var repoPath string + var cleanup testhelper.Cleanup + if bare { + repo, repoPath, cleanup = gittest.CloneRepoAtStorage(t, cfg.Storages[0], t.Name()) + t.Cleanup(cleanup) + } else { + repo, repoPath, cleanup = gittest.CloneRepoWithWorktreeAtStorage(t, cfg.Storages[0]) + t.Cleanup(cleanup) } - defer RubyServer.Stop() - return m.Run() + serverSocketPath, stop := runConflictsServer(t, cfg, rubySrv) + t.Cleanup(stop) + cfg.SocketPath = serverSocketPath + + client, conn := NewConflictsClient(t, serverSocketPath) + t.Cleanup(func() { conn.Close() }) + + return cfg, repo, repoPath, client +} + +func SetupConflictsService(t testing.TB, bare bool) (config.Cfg, *gitalypb.Repository, string, gitalypb.ConflictsServiceClient) { + cfg := testcfg.Build(t) + + return SetupConflictsServiceWithRuby(t, cfg, nil, bare) } -func runConflictsServer(t *testing.T) (string, func()) { +func runConflictsServer(t testing.TB, cfg config.Cfg, rubySrv *rubyserver.Server) (string, func()) { srv := testhelper.NewServer(t, nil, nil) - locator := config.NewLocator(config.Config) - gitCmdFactory := git.NewExecCommandFactory(config.Config) + locator := config.NewLocator(cfg) + gitCmdFactory := git.NewExecCommandFactory(cfg) + txManager := transaction.NewManager(cfg) - gitalypb.RegisterConflictsServiceServer(srv.GrpcServer(), NewServer(RubyServer, config.Config, locator, gitCmdFactory)) - reflection.Register(srv.GrpcServer()) + gitalypb.RegisterConflictsServiceServer(srv.GrpcServer(), NewServer(rubySrv, cfg, locator, gitCmdFactory)) + gitalypb.RegisterRepositoryServiceServer(srv.GrpcServer(), repository.NewServer(cfg, rubySrv, locator, txManager, gitCmdFactory)) srv.Start(t) return "unix://" + srv.Socket(), srv.Stop } -func NewConflictsClient(t *testing.T, serverSocketPath string) (gitalypb.ConflictsServiceClient, *grpc.ClientConn) { +func NewConflictsClient(t testing.TB, serverSocketPath string) (gitalypb.ConflictsServiceClient, *grpc.ClientConn) { connOpts := []grpc.DialOption{ grpc.WithInsecure(), } diff --git a/internal/testhelper/configure.go b/internal/testhelper/configure.go index 8aa12232f..8a92e54d7 100644 --- a/internal/testhelper/configure.go +++ b/internal/testhelper/configure.go @@ -134,22 +134,27 @@ func ConfigureRuby(cfg *config.Cfg) error { // ConfigureGitalyGit2Go configures the gitaly-git2go command for tests func ConfigureGitalyGit2Go(outputDir string) { - buildCommand(outputDir, "gitaly-git2go") + buildCommand(nil, outputDir, "gitaly-git2go") +} + +// ConfigureGitalyGit2GoBin configures the gitaly-git2go command for tests +func ConfigureGitalyGit2GoBin(t testing.TB, cfg config.Cfg) { + buildBinary(t, cfg.BinDir, "gitaly-git2go") } // ConfigureGitalyLfsSmudge configures the gitaly-lfs-smudge command for tests func ConfigureGitalyLfsSmudge(outputDir string) { - buildCommand(outputDir, "gitaly-lfs-smudge") + buildCommand(nil, outputDir, "gitaly-lfs-smudge") } // ConfigureGitalySSH configures the gitaly-ssh command for tests func ConfigureGitalySSH(outputDir string) { - buildCommand(outputDir, "gitaly-ssh") + buildCommand(nil, outputDir, "gitaly-ssh") } // ConfigureGitalyHooksBinary builds gitaly-hooks command for tests func ConfigureGitalyHooksBinary(outputDir string) { - buildCommand(outputDir, "gitaly-hooks") + buildCommand(nil, outputDir, "gitaly-hooks") } // ConfigureGitalyHooksBin builds gitaly-hooks command for tests for the cfg. @@ -207,11 +212,11 @@ func buildBinary(t testing.TB, dstDir, name string) { // something went wrong and for some reason the binary already exists require.FailNow(t, err.Error()) } - buildCommand(binsPath, name) + buildCommand(t, binsPath, name) } } -func buildCommand(outputDir, cmd string) { +func buildCommand(t testing.TB, outputDir, cmd string) { if outputDir == "" { log.Fatal("BinDir must be set") } @@ -222,5 +227,5 @@ func buildCommand(outputDir, cmd string) { "-o", filepath.Join(outputDir, cmd), fmt.Sprintf("gitlab.com/gitlab-org/gitaly/cmd/%s", cmd), } - MustRunCommand(nil, nil, "go", goBuildArgs...) + MustRunCommand(t, nil, "go", goBuildArgs...) } |