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:
authorPavlo Strokov <pstrokov@gitlab.com>2021-03-22 11:08:38 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2021-03-22 11:08:38 +0300
commit712d87a0ae9445fb9c0d67eb7257865bdf2236bb (patch)
tree0b83c3b8234afdd605206f7b7e5680092b89ad62
parent6314c40a2e0ae9d43eb4c01026d0aef57c10d91c (diff)
parent8f86e7fe8ae03f4667bef7ab9c8033f81b046484 (diff)
Merge branch 'ps-rm-config-diff' into 'master'
Removal of config.Config from diff package See merge request gitlab-org/gitaly!3275
-rw-r--r--internal/gitaly/service/diff/commit_test.go274
-rw-r--r--internal/gitaly/service/diff/find_changed_paths_test.go31
-rw-r--r--internal/gitaly/service/diff/numstat_test.go39
-rw-r--r--internal/gitaly/service/diff/raw_test.go63
-rw-r--r--internal/gitaly/service/diff/testhelper_test.go31
5 files changed, 113 insertions, 325 deletions
diff --git a/internal/gitaly/service/diff/commit_test.go b/internal/gitaly/service/diff/commit_test.go
index 759d0c853..502814029 100644
--- a/internal/gitaly/service/diff/commit_test.go
+++ b/internal/gitaly/service/diff/commit_test.go
@@ -1,14 +1,12 @@
package diff
import (
- "bytes"
"fmt"
"io"
"testing"
"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/gitaly/diff"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -16,14 +14,7 @@ import (
)
func TestSuccessfulCommitDiffRequest(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
-
- testRepo, testRepoPath, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
+ _, repo, repoPath, client := setupDiffService(t)
rightCommit := "ab2c9622c02288a2bbaaf35d96088cfdff31d9d9"
leftCommit := "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab"
@@ -177,15 +168,13 @@ func TestSuccessfulCommitDiffRequest(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "config", "diff.noprefix", testCase.noPrefixConfig)
- rpcRequest := &gitalypb.CommitDiffRequest{Repository: testRepo, RightCommitId: rightCommit, LeftCommitId: leftCommit, IgnoreWhitespaceChange: false}
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "config", "diff.noprefix", testCase.noPrefixConfig)
+ rpcRequest := &gitalypb.CommitDiffRequest{Repository: repo, RightCommitId: rightCommit, LeftCommitId: leftCommit, IgnoreWhitespaceChange: false}
ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDiff(ctx, rpcRequest)
- if err != nil {
- t.Fatal(err)
- }
+ require.NoError(t, err)
assertExactReceivedDiffs(t, c, expectedDiffs)
})
@@ -193,19 +182,12 @@ func TestSuccessfulCommitDiffRequest(t *testing.T) {
}
func TestSuccessfulCommitDiffRequestWithPaths(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
-
- testRepo, _, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
+ _, repo, _, client := setupDiffService(t)
rightCommit := "e4003da16c1c2c3fc4567700121b17bf8e591c6c"
leftCommit := "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab"
rpcRequest := &gitalypb.CommitDiffRequest{
- Repository: testRepo,
+ Repository: repo,
RightCommitId: rightCommit,
LeftCommitId: leftCommit,
IgnoreWhitespaceChange: false,
@@ -220,9 +202,7 @@ func TestSuccessfulCommitDiffRequestWithPaths(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDiff(ctx, rpcRequest)
- if err != nil {
- t.Fatal(err)
- }
+ require.NoError(t, err)
expectedDiffs := []diff.Diff{
{
@@ -271,19 +251,12 @@ func TestSuccessfulCommitDiffRequestWithPaths(t *testing.T) {
}
func TestSuccessfulCommitDiffRequestWithTypeChangeDiff(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
-
- testRepo, _, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
+ _, repo, _, client := setupDiffService(t)
rightCommit := "184a47d38677e2e439964859b877ae9bc424ab11"
leftCommit := "80d56eb72ba5d77fd8af857eced17a7d0640cb82"
rpcRequest := &gitalypb.CommitDiffRequest{
- Repository: testRepo,
+ Repository: repo,
RightCommitId: rightCommit,
LeftCommitId: leftCommit,
}
@@ -291,9 +264,7 @@ func TestSuccessfulCommitDiffRequestWithTypeChangeDiff(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDiff(ctx, rpcRequest)
- if err != nil {
- t.Fatal(err)
- }
+ require.NoError(t, err)
expectedDiffs := []diff.Diff{
{
@@ -322,14 +293,7 @@ func TestSuccessfulCommitDiffRequestWithTypeChangeDiff(t *testing.T) {
}
func TestSuccessfulCommitDiffRequestWithIgnoreWhitespaceChange(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
-
- testRepo, _, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
+ _, repo, _, client := setupDiffService(t)
rightCommit := "e4003da16c1c2c3fc4567700121b17bf8e591c6c"
leftCommit := "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab"
@@ -416,7 +380,7 @@ func TestSuccessfulCommitDiffRequestWithIgnoreWhitespaceChange(t *testing.T) {
for _, entry := range pathsAndDiffs {
t.Run(entry.desc, func(t *testing.T) {
rpcRequest := &gitalypb.CommitDiffRequest{
- Repository: testRepo,
+ Repository: repo,
RightCommitId: rightCommit,
LeftCommitId: leftCommit,
IgnoreWhitespaceChange: true,
@@ -426,9 +390,7 @@ func TestSuccessfulCommitDiffRequestWithIgnoreWhitespaceChange(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDiff(ctx, rpcRequest)
- if err != nil {
- t.Fatal(err)
- }
+ require.NoError(t, err)
assertExactReceivedDiffs(t, c, entry.diffs)
})
@@ -436,14 +398,7 @@ func TestSuccessfulCommitDiffRequestWithIgnoreWhitespaceChange(t *testing.T) {
}
func TestSuccessfulCommitDiffRequestWithLimits(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
-
- testRepo, _, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
+ _, repo, _, client := setupDiffService(t)
rightCommit := "899d3d27b04690ac1cd9ef4d8a74fde0667c57f1"
leftCommit := "184a47d38677e2e439964859b877ae9bc424ab11"
@@ -627,16 +582,14 @@ func TestSuccessfulCommitDiffRequestWithLimits(t *testing.T) {
for _, requestAndResult := range requestsAndResults {
t.Run(requestAndResult.desc, func(t *testing.T) {
request := requestAndResult.request
- request.Repository = testRepo
+ request.Repository = repo
request.LeftCommitId = leftCommit
request.RightCommitId = rightCommit
ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDiff(ctx, &request)
- if err != nil {
- t.Fatal(err)
- }
+ require.NoError(t, err)
receivedDiffs := getDiffsFromCommitDiffClient(t, c)
@@ -658,14 +611,7 @@ func TestSuccessfulCommitDiffRequestWithLimits(t *testing.T) {
}
func TestFailedCommitDiffRequestDueToValidationError(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
-
- testRepo, _, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
+ _, repo, _, client := setupDiffService(t)
rightCommit := "d42783470dc29fde2cf459eb3199ee1d7e3f3a72"
leftCommit := rightCommit + "~" // Parent of rightCommit
@@ -673,8 +619,8 @@ func TestFailedCommitDiffRequestDueToValidationError(t *testing.T) {
rpcRequests := []gitalypb.CommitDiffRequest{
{Repository: &gitalypb.Repository{StorageName: "fake", RelativePath: "path"}, RightCommitId: rightCommit, LeftCommitId: leftCommit}, // Repository doesn't exist
{Repository: nil, RightCommitId: rightCommit, LeftCommitId: leftCommit}, // Repository is nil
- {Repository: testRepo, RightCommitId: "", LeftCommitId: leftCommit}, // RightCommitId is empty
- {Repository: testRepo, RightCommitId: rightCommit, LeftCommitId: ""}, // LeftCommitId is empty
+ {Repository: repo, RightCommitId: "", LeftCommitId: leftCommit}, // RightCommitId is empty
+ {Repository: repo, RightCommitId: rightCommit, LeftCommitId: ""}, // LeftCommitId is empty
}
for _, rpcRequest := range rpcRequests {
@@ -682,9 +628,7 @@ func TestFailedCommitDiffRequestDueToValidationError(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDiff(ctx, &rpcRequest)
- if err != nil {
- t.Fatal(err)
- }
+ require.NoError(t, err)
err = drainCommitDiffResponse(c)
testhelper.RequireGrpcError(t, err, codes.InvalidArgument)
@@ -693,50 +637,32 @@ func TestFailedCommitDiffRequestDueToValidationError(t *testing.T) {
}
func TestFailedCommitDiffRequestWithNonExistentCommit(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
-
- testRepo, _, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
+ _, repo, _, client := setupDiffService(t)
nonExistentCommitID := "deadfacedeadfacedeadfacedeadfacedeadface"
leftCommit := nonExistentCommitID + "~" // Parent of rightCommit
- rpcRequest := &gitalypb.CommitDiffRequest{Repository: testRepo, RightCommitId: nonExistentCommitID, LeftCommitId: leftCommit}
+ rpcRequest := &gitalypb.CommitDiffRequest{Repository: repo, RightCommitId: nonExistentCommitID, LeftCommitId: leftCommit}
ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDiff(ctx, rpcRequest)
- if err != nil {
- t.Fatal(err)
- }
+ require.NoError(t, err)
err = drainCommitDiffResponse(c)
testhelper.RequireGrpcError(t, err, codes.Unavailable)
}
func TestSuccessfulCommitDeltaRequest(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
-
- testRepo, _, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
+ _, repo, _, client := setupDiffService(t)
rightCommit := "742518b2be68fc750bb4c357c0df821a88113286"
leftCommit := "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab"
- rpcRequest := &gitalypb.CommitDeltaRequest{Repository: testRepo, RightCommitId: rightCommit, LeftCommitId: leftCommit}
+ rpcRequest := &gitalypb.CommitDeltaRequest{Repository: repo, RightCommitId: rightCommit, LeftCommitId: leftCommit}
ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDelta(ctx, rpcRequest)
- if err != nil {
- t.Fatal(err)
- }
+ require.NoError(t, err)
expectedDeltas := []diff.Diff{
{
@@ -841,19 +767,12 @@ func TestSuccessfulCommitDeltaRequest(t *testing.T) {
}
func TestSuccessfulCommitDeltaRequestWithPaths(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
-
- testRepo, _, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
+ _, repo, _, client := setupDiffService(t)
rightCommit := "e4003da16c1c2c3fc4567700121b17bf8e591c6c"
leftCommit := "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab"
rpcRequest := &gitalypb.CommitDeltaRequest{
- Repository: testRepo,
+ Repository: repo,
RightCommitId: rightCommit,
LeftCommitId: leftCommit,
Paths: [][]byte{
@@ -867,9 +786,7 @@ func TestSuccessfulCommitDeltaRequestWithPaths(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDelta(ctx, rpcRequest)
- if err != nil {
- t.Fatal(err)
- }
+ require.NoError(t, err)
expectedDeltas := []diff.Diff{
{
@@ -910,14 +827,7 @@ func TestSuccessfulCommitDeltaRequestWithPaths(t *testing.T) {
}
func TestFailedCommitDeltaRequestDueToValidationError(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
-
- testRepo, _, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
+ _, repo, _, client := setupDiffService(t)
rightCommit := "d42783470dc29fde2cf459eb3199ee1d7e3f3a72"
leftCommit := rightCommit + "~" // Parent of rightCommit
@@ -925,8 +835,8 @@ func TestFailedCommitDeltaRequestDueToValidationError(t *testing.T) {
rpcRequests := []gitalypb.CommitDeltaRequest{
{Repository: &gitalypb.Repository{StorageName: "fake", RelativePath: "path"}, RightCommitId: rightCommit, LeftCommitId: leftCommit}, // Repository doesn't exist
{Repository: nil, RightCommitId: rightCommit, LeftCommitId: leftCommit}, // Repository is nil
- {Repository: testRepo, RightCommitId: "", LeftCommitId: leftCommit}, // RightCommitId is empty
- {Repository: testRepo, RightCommitId: rightCommit, LeftCommitId: ""}, // LeftCommitId is empty
+ {Repository: repo, RightCommitId: "", LeftCommitId: leftCommit}, // RightCommitId is empty
+ {Repository: repo, RightCommitId: rightCommit, LeftCommitId: ""}, // LeftCommitId is empty
}
for _, rpcRequest := range rpcRequests {
@@ -934,9 +844,7 @@ func TestFailedCommitDeltaRequestDueToValidationError(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDelta(ctx, &rpcRequest)
- if err != nil {
- t.Fatal(err)
- }
+ require.NoError(t, err)
err = drainCommitDeltaResponse(c)
testhelper.RequireGrpcError(t, err, codes.InvalidArgument)
@@ -945,25 +853,16 @@ func TestFailedCommitDeltaRequestDueToValidationError(t *testing.T) {
}
func TestFailedCommitDeltaRequestWithNonExistentCommit(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
-
- testRepo, _, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
+ _, repo, _, client := setupDiffService(t)
nonExistentCommitID := "deadfacedeadfacedeadfacedeadfacedeadface"
leftCommit := nonExistentCommitID + "~" // Parent of rightCommit
- rpcRequest := &gitalypb.CommitDeltaRequest{Repository: testRepo, RightCommitId: nonExistentCommitID, LeftCommitId: leftCommit}
+ rpcRequest := &gitalypb.CommitDeltaRequest{Repository: repo, RightCommitId: nonExistentCommitID, LeftCommitId: leftCommit}
ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDelta(ctx, rpcRequest)
- if err != nil {
- t.Fatal(err)
- }
+ require.NoError(t, err)
err = drainCommitDeltaResponse(c)
testhelper.RequireGrpcError(t, err, codes.Unavailable)
@@ -995,9 +894,8 @@ func getDiffsFromCommitDiffClient(t *testing.T, client gitalypb.DiffService_Comm
fetchedDiff, err := client.Recv()
if err == io.EOF {
break
- } else if err != nil {
- t.Fatal(err)
}
+ require.NoError(t, err)
if currentDiff == nil {
currentDiff = &diff.Diff{
@@ -1033,98 +931,48 @@ func assertExactReceivedDiffs(t *testing.T, client gitalypb.DiffService_CommitDi
var fetchedDiff *diff.Diff
for i, fetchedDiff = range fetchedDiffs {
- if i >= len(expectedDiffs) {
- t.Errorf("Unexpected diff #%d received: %v", i, fetchedDiff)
- break
- }
+ require.Greater(t, len(expectedDiffs), i, "Unexpected diff #%d received: %v", i, fetchedDiff)
expectedDiff := expectedDiffs[i]
-
- if expectedDiff.FromID != fetchedDiff.FromID {
- t.Errorf("Expected diff #%d FromID to equal = %q, got %q", i, expectedDiff.FromID, fetchedDiff.FromID)
- }
-
- if expectedDiff.ToID != fetchedDiff.ToID {
- t.Errorf("Expected diff #%d ToID to equal = %q, got %q", i, expectedDiff.ToID, fetchedDiff.ToID)
- }
-
- if expectedDiff.OldMode != fetchedDiff.OldMode {
- t.Errorf("Expected diff #%d OldMode to equal = %o, got %o", i, expectedDiff.OldMode, fetchedDiff.OldMode)
- }
-
- if expectedDiff.NewMode != fetchedDiff.NewMode {
- t.Errorf("Expected diff #%d NewMode to equal = %o, got %o", i, expectedDiff.NewMode, fetchedDiff.NewMode)
- }
-
- if !bytes.Equal(expectedDiff.FromPath, fetchedDiff.FromPath) {
- t.Errorf("Expected diff #%d FromPath to equal = %q, got %q", i, expectedDiff.FromPath, fetchedDiff.FromPath)
- }
-
- if !bytes.Equal(expectedDiff.ToPath, fetchedDiff.ToPath) {
- t.Errorf("Expected diff #%d ToPath to equal = %q, got %q", i, expectedDiff.ToPath, fetchedDiff.ToPath)
- }
-
- if expectedDiff.Binary != fetchedDiff.Binary {
- t.Errorf("Expected diff #%d Binary to be %t, got %t", i, expectedDiff.Binary, fetchedDiff.Binary)
- }
-
- if !bytes.Equal(expectedDiff.Patch, fetchedDiff.Patch) {
- t.Errorf("Expected diff #%d Chunks to be %q, got %q", i, expectedDiff.Patch, fetchedDiff.Patch)
- }
+ require.Equal(t, expectedDiff.FromID, fetchedDiff.FromID)
+ require.Equal(t, expectedDiff.ToID, fetchedDiff.ToID)
+ require.Equal(t, expectedDiff.OldMode, fetchedDiff.OldMode)
+ require.Equal(t, expectedDiff.NewMode, fetchedDiff.NewMode)
+ require.Equal(t, expectedDiff.FromPath, fetchedDiff.FromPath)
+ require.Equal(t, expectedDiff.ToPath, fetchedDiff.ToPath)
+ require.Equal(t, expectedDiff.Binary, fetchedDiff.Binary)
+ require.Equal(t, expectedDiff.Patch, fetchedDiff.Patch)
}
- if len(expectedDiffs) != i+1 {
- t.Errorf("Expected number of diffs to be %d, got %d", len(expectedDiffs), i+1)
- }
+ require.Len(t, expectedDiffs, i+1, "Unexpected number of diffs")
}
func assertExactReceivedDeltas(t *testing.T, client gitalypb.DiffService_CommitDeltaClient, expectedDeltas []diff.Diff) {
- i := 0
+ t.Helper()
+
+ counter := 0
for {
fetchedDeltas, err := client.Recv()
if err == io.EOF {
break
- } else if err != nil {
- t.Fatal(err)
}
+ require.NoError(t, err)
for _, fetchedDelta := range fetchedDeltas.GetDeltas() {
- if i >= len(expectedDeltas) {
- t.Errorf("Unexpected delta #%d received: %v", i, fetchedDelta)
- break
- }
-
- expectedDelta := expectedDeltas[i]
-
- if expectedDelta.FromID != fetchedDelta.FromId {
- t.Errorf("Expected delta #%d FromID to equal = %q, got %q", i, expectedDelta.FromID, fetchedDelta.FromId)
- }
-
- if expectedDelta.ToID != fetchedDelta.ToId {
- t.Errorf("Expected delta #%d ToID to equal = %q, got %q", i, expectedDelta.ToID, fetchedDelta.ToId)
- }
-
- if expectedDelta.OldMode != fetchedDelta.OldMode {
- t.Errorf("Expected delta #%d OldMode to equal = %o, got %o", i, expectedDelta.OldMode, fetchedDelta.OldMode)
- }
-
- if expectedDelta.NewMode != fetchedDelta.NewMode {
- t.Errorf("Expected delta #%d NewMode to equal = %o, got %o", i, expectedDelta.NewMode, fetchedDelta.NewMode)
- }
+ require.GreaterOrEqual(t, len(expectedDeltas), counter, "Unexpected delta #%d received: %v", counter, fetchedDelta)
- if !bytes.Equal(expectedDelta.FromPath, fetchedDelta.FromPath) {
- t.Errorf("Expected delta #%d FromPath to equal = %q, got %q", i, expectedDelta.FromPath, fetchedDelta.FromPath)
- }
+ expectedDelta := expectedDeltas[counter]
- if !bytes.Equal(expectedDelta.ToPath, fetchedDelta.ToPath) {
- t.Errorf("Expected delta #%d ToPath to equal = %q, got %q", i, expectedDelta.ToPath, fetchedDelta.ToPath)
- }
+ require.Equal(t, expectedDelta.FromID, fetchedDelta.FromId)
+ require.Equal(t, expectedDelta.ToID, fetchedDelta.ToId)
+ require.Equal(t, expectedDelta.OldMode, fetchedDelta.OldMode)
+ require.Equal(t, expectedDelta.NewMode, fetchedDelta.NewMode)
+ require.Equal(t, expectedDelta.FromPath, fetchedDelta.FromPath)
+ require.Equal(t, expectedDelta.ToPath, fetchedDelta.ToPath)
- i++
+ counter++
}
}
- if len(expectedDeltas) != i {
- t.Errorf("Expected number of deltas to be %d, got %d", len(expectedDeltas), i)
- }
+ require.Len(t, expectedDeltas, counter, "Unexpected number of deltas")
}
diff --git a/internal/gitaly/service/diff/find_changed_paths_test.go b/internal/gitaly/service/diff/find_changed_paths_test.go
index ce5fe3e89..b1c699fc9 100644
--- a/internal/gitaly/service/diff/find_changed_paths_test.go
+++ b/internal/gitaly/service/diff/find_changed_paths_test.go
@@ -6,7 +6,6 @@ import (
"testing"
"github.com/stretchr/testify/require"
- "gitlab.com/gitlab-org/gitaly/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -14,14 +13,7 @@ import (
)
func TestFindChangedPathsRequest_success(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
-
- testRepo, _, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
+ _, repo, _, client := setupDiffService(t)
ctx, cancel := testhelper.Context()
defer cancel()
@@ -95,7 +87,7 @@ func TestFindChangedPathsRequest_success(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- rpcRequest := &gitalypb.FindChangedPathsRequest{Repository: testRepo, Commits: tc.commits}
+ rpcRequest := &gitalypb.FindChangedPathsRequest{Repository: repo, Commits: tc.commits}
stream, err := client.FindChangedPaths(ctx, rpcRequest)
require.NoError(t, err)
@@ -118,18 +110,11 @@ func TestFindChangedPathsRequest_success(t *testing.T) {
}
func TestFindChangedPathsRequest_failing(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
+ cfg, repo, _, client := setupDiffService(t)
ctx, cancel := testhelper.Context()
defer cancel()
- testRepo, _, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
-
tests := []struct {
desc string
repo *gitalypb.Repository
@@ -138,9 +123,9 @@ func TestFindChangedPathsRequest_failing(t *testing.T) {
}{
{
desc: "Repo not found",
- repo: &gitalypb.Repository{StorageName: testRepo.GetStorageName(), RelativePath: "bar.git"},
+ repo: &gitalypb.Repository{StorageName: repo.GetStorageName(), RelativePath: "bar.git"},
commits: []string{"e4003da16c1c2c3fc4567700121b17bf8e591c6c", "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab"},
- err: status.Errorf(codes.NotFound, "GetRepoPath: not a git repository: %q", filepath.Join(testhelper.GitlabTestStoragePath(), "bar.git")),
+ err: status.Errorf(codes.NotFound, "GetRepoPath: not a git repository: %q", filepath.Join(cfg.Storages[0].Path, "bar.git")),
},
{
desc: "Storage not found",
@@ -150,19 +135,19 @@ func TestFindChangedPathsRequest_failing(t *testing.T) {
},
{
desc: "Commits cannot contain an empty commit",
- repo: testRepo,
+ repo: repo,
commits: []string{""},
err: status.Error(codes.InvalidArgument, "FindChangedPaths: commits cannot contain an empty commit"),
},
{
desc: "Invalid commit",
- repo: testRepo,
+ repo: repo,
commits: []string{"invalidinvalidinvalid", "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab"},
err: status.Error(codes.NotFound, "FindChangedPaths: commit: invalidinvalidinvalid can not be found"),
},
{
desc: "Commit not found",
- repo: testRepo,
+ repo: repo,
commits: []string{"z4003da16c1c2c3fc4567700121b17bf8e591c6c", "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab"},
err: status.Error(codes.NotFound, "FindChangedPaths: commit: z4003da16c1c2c3fc4567700121b17bf8e591c6c can not be found"),
},
diff --git a/internal/gitaly/service/diff/numstat_test.go b/internal/gitaly/service/diff/numstat_test.go
index 32c565e61..713277c43 100644
--- a/internal/gitaly/service/diff/numstat_test.go
+++ b/internal/gitaly/service/diff/numstat_test.go
@@ -5,7 +5,6 @@ import (
"testing"
"github.com/stretchr/testify/require"
- "gitlab.com/gitlab-org/gitaly/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/diff"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -13,18 +12,11 @@ import (
)
func TestSuccessfulDiffStatsRequest(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
-
- testRepo, _, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
+ _, repo, _, client := setupDiffService(t)
rightCommit := "e4003da16c1c2c3fc4567700121b17bf8e591c6c"
leftCommit := "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab"
- rpcRequest := &gitalypb.DiffStatsRequest{Repository: testRepo, RightCommitId: rightCommit, LeftCommitId: leftCommit}
+ rpcRequest := &gitalypb.DiffStatsRequest{Repository: repo, RightCommitId: rightCommit, LeftCommitId: leftCommit}
ctx, cancel := testhelper.Context()
defer cancel()
@@ -103,9 +95,7 @@ func TestSuccessfulDiffStatsRequest(t *testing.T) {
}
stream, err := client.DiffStats(ctx, rpcRequest)
- if err != nil {
- t.Fatal(err)
- }
+ require.NoError(t, err)
for {
fetchedStats, err := stream.Recv()
@@ -128,18 +118,11 @@ func TestSuccessfulDiffStatsRequest(t *testing.T) {
}
func TestFailedDiffStatsRequest(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
+ _, repo, _, client := setupDiffService(t)
ctx, cancel := testhelper.Context()
defer cancel()
- testRepo, _, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
-
tests := []struct {
desc string
repo *gitalypb.Repository
@@ -149,7 +132,7 @@ func TestFailedDiffStatsRequest(t *testing.T) {
}{
{
desc: "repo not found",
- repo: &gitalypb.Repository{StorageName: testRepo.GetStorageName(), RelativePath: "bar.git"},
+ repo: &gitalypb.Repository{StorageName: repo.GetStorageName(), RelativePath: "bar.git"},
leftCommitID: "e4003da16c1c2c3fc4567700121b17bf8e591c6c",
rightCommitID: "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab",
err: codes.NotFound,
@@ -163,42 +146,42 @@ func TestFailedDiffStatsRequest(t *testing.T) {
},
{
desc: "left commit ID not found",
- repo: testRepo,
+ repo: repo,
leftCommitID: "",
rightCommitID: "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab",
err: codes.InvalidArgument,
},
{
desc: "right commit ID not found",
- repo: testRepo,
+ repo: repo,
leftCommitID: "e4003da16c1c2c3fc4567700121b17bf8e591c6c",
rightCommitID: "",
err: codes.InvalidArgument,
},
{
desc: "invalid left commit",
- repo: testRepo,
+ repo: repo,
leftCommitID: "invalidinvalidinvalid",
rightCommitID: "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab",
err: codes.Unavailable,
},
{
desc: "invalid right commit",
- repo: testRepo,
+ repo: repo,
leftCommitID: "e4003da16c1c2c3fc4567700121b17bf8e591c6c",
rightCommitID: "invalidinvalidinvalid",
err: codes.Unavailable,
},
{
desc: "left commit not found",
- repo: testRepo,
+ repo: repo,
leftCommitID: "z4003da16c1c2c3fc4567700121b17bf8e591c6c",
rightCommitID: "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab",
err: codes.Unavailable,
},
{
desc: "right commit not found",
- repo: testRepo,
+ repo: repo,
leftCommitID: "e4003da16c1c2c3fc4567700121b17bf8e591c6c",
rightCommitID: "z4003da16c1c2c3fc4567700121b17bf8e591c6c",
err: codes.Unavailable,
diff --git a/internal/gitaly/service/diff/raw_test.go b/internal/gitaly/service/diff/raw_test.go
index 635046fa3..6c9214f37 100644
--- a/internal/gitaly/service/diff/raw_test.go
+++ b/internal/gitaly/service/diff/raw_test.go
@@ -15,21 +15,14 @@ import (
)
func TestSuccessfulRawDiffRequest(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
+ _, repo, repoPath, client := setupDiffService(t)
ctx, cancel := testhelper.Context()
defer cancel()
- testRepo, testRepoPath, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
-
rightCommit := "e395f646b1499e8e0279445fc99a0596a65fab7e"
leftCommit := "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab"
- rpcRequest := &gitalypb.RawDiffRequest{Repository: testRepo, RightCommitId: rightCommit, LeftCommitId: leftCommit}
+ rpcRequest := &gitalypb.RawDiffRequest{Repository: repo, RightCommitId: rightCommit, LeftCommitId: leftCommit}
c, err := client.RawDiff(ctx, rpcRequest)
require.NoError(t, err)
@@ -53,20 +46,13 @@ func TestSuccessfulRawDiffRequest(t *testing.T) {
"-c", fmt.Sprintf("user.email=%s", committerEmail),
"commit", "-m", "Applying received raw diff")
- expectedTreeStructure := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "ls-tree", "-r", rightCommit)
+ expectedTreeStructure := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "ls-tree", "-r", rightCommit)
actualTreeStructure := testhelper.MustRunCommand(t, nil, "git", "-C", sandboxRepoPath, "ls-tree", "-r", "HEAD")
require.Equal(t, expectedTreeStructure, actualTreeStructure)
}
func TestFailedRawDiffRequestDueToValidations(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
-
- testRepo, _, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
+ _, repo, _, client := setupDiffService(t)
testCases := []struct {
desc string
@@ -76,7 +62,7 @@ func TestFailedRawDiffRequestDueToValidations(t *testing.T) {
{
desc: "empty left commit",
request: &gitalypb.RawDiffRequest{
- Repository: testRepo,
+ Repository: repo,
LeftCommitId: "",
RightCommitId: "e395f646b1499e8e0279445fc99a0596a65fab7e",
},
@@ -85,7 +71,7 @@ func TestFailedRawDiffRequestDueToValidations(t *testing.T) {
{
desc: "empty right commit",
request: &gitalypb.RawDiffRequest{
- Repository: testRepo,
+ Repository: repo,
RightCommitId: "",
LeftCommitId: "e395f646b1499e8e0279445fc99a0596a65fab7e",
},
@@ -114,21 +100,14 @@ func TestFailedRawDiffRequestDueToValidations(t *testing.T) {
}
func TestSuccessfulRawPatchRequest(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
+ _, repo, repoPath, client := setupDiffService(t)
ctx, cancel := testhelper.Context()
defer cancel()
- testRepo, testRepoPath, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
-
rightCommit := "e395f646b1499e8e0279445fc99a0596a65fab7e"
leftCommit := "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab"
- rpcRequest := &gitalypb.RawPatchRequest{Repository: testRepo, RightCommitId: rightCommit, LeftCommitId: leftCommit}
+ rpcRequest := &gitalypb.RawPatchRequest{Repository: repo, RightCommitId: rightCommit, LeftCommitId: leftCommit}
c, err := client.RawPatch(ctx, rpcRequest)
require.NoError(t, err)
@@ -145,20 +124,13 @@ func TestSuccessfulRawPatchRequest(t *testing.T) {
testhelper.MustRunCommand(t, reader, "git", "-C", sandboxRepoPath, "am")
- expectedTreeStructure := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "ls-tree", "-r", rightCommit)
+ expectedTreeStructure := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "ls-tree", "-r", rightCommit)
actualTreeStructure := testhelper.MustRunCommand(t, nil, "git", "-C", sandboxRepoPath, "ls-tree", "-r", "HEAD")
require.Equal(t, expectedTreeStructure, actualTreeStructure)
}
func TestFailedRawPatchRequestDueToValidations(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
-
- testRepo, _, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
+ _, repo, _, client := setupDiffService(t)
testCases := []struct {
desc string
@@ -168,7 +140,7 @@ func TestFailedRawPatchRequestDueToValidations(t *testing.T) {
{
desc: "empty left commit",
request: &gitalypb.RawPatchRequest{
- Repository: testRepo,
+ Repository: repo,
LeftCommitId: "",
RightCommitId: "e395f646b1499e8e0279445fc99a0596a65fab7e",
},
@@ -177,7 +149,7 @@ func TestFailedRawPatchRequestDueToValidations(t *testing.T) {
{
desc: "empty right commit",
request: &gitalypb.RawPatchRequest{
- Repository: testRepo,
+ Repository: repo,
RightCommitId: "",
LeftCommitId: "e395f646b1499e8e0279445fc99a0596a65fab7e",
},
@@ -206,21 +178,14 @@ func TestFailedRawPatchRequestDueToValidations(t *testing.T) {
}
func TestRawPatchContainsGitLabSignature(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
-
- client, conn := newDiffClient(t, serverSocketPath)
- defer conn.Close()
+ _, repo, _, client := setupDiffService(t)
ctx, cancel := testhelper.Context()
defer cancel()
- testRepo, _, cleanupFn := gittest.CloneRepo(t)
- defer cleanupFn()
-
rightCommit := "e395f646b1499e8e0279445fc99a0596a65fab7e"
leftCommit := "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab"
- rpcRequest := &gitalypb.RawPatchRequest{Repository: testRepo, RightCommitId: rightCommit, LeftCommitId: leftCommit}
+ rpcRequest := &gitalypb.RawPatchRequest{Repository: repo, RightCommitId: rightCommit, LeftCommitId: leftCommit}
c, err := client.RawPatch(ctx, rpcRequest)
require.NoError(t, err)
diff --git a/internal/gitaly/service/diff/testhelper_test.go b/internal/gitaly/service/diff/testhelper_test.go
index 3a1ad4586..00be98713 100644
--- a/internal/gitaly/service/diff/testhelper_test.go
+++ b/internal/gitaly/service/diff/testhelper_test.go
@@ -5,12 +5,13 @@ import (
"os"
"testing"
+ "github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"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"
)
func TestMain(m *testing.M) {
@@ -24,33 +25,39 @@ func testMain(m *testing.M) int {
return m.Run()
}
-func runDiffServer(t *testing.T) (*grpc.Server, string) {
+func setupDiffService(t testing.TB) (config.Cfg, *gitalypb.Repository, string, gitalypb.DiffServiceClient) {
+ cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ cfg.SocketPath = runDiffServer(t, cfg)
+ client, conn := newDiffClient(t, cfg.SocketPath)
+ t.Cleanup(func() { conn.Close() })
+
+ return cfg, repo, repoPath, client
+}
+
+func runDiffServer(t testing.TB, cfg config.Cfg) string {
+ t.Helper()
+
server := testhelper.NewTestGrpcServer(t, nil, nil)
+ t.Cleanup(server.Stop)
serverSocketPath := testhelper.GetTemporaryGitalySocketFileName(t)
listener, err := net.Listen("unix", serverSocketPath)
- if err != nil {
- t.Fatal(err)
- }
+ require.NoError(t, err)
- cfg := config.Config
gitalypb.RegisterDiffServiceServer(server, NewServer(cfg, config.NewLocator(cfg), git.NewExecCommandFactory(cfg)))
- reflection.Register(server)
go server.Serve(listener)
- return server, "unix://" + serverSocketPath
+ return "unix://" + serverSocketPath
}
-func newDiffClient(t *testing.T, serverSocketPath string) (gitalypb.DiffServiceClient, *grpc.ClientConn) {
+func newDiffClient(t testing.TB, serverSocketPath string) (gitalypb.DiffServiceClient, *grpc.ClientConn) {
connOpts := []grpc.DialOption{
grpc.WithInsecure(),
}
conn, err := grpc.Dial(serverSocketPath, connOpts...)
- if err != nil {
- t.Fatal(err)
- }
+ require.NoError(t, err)
return gitalypb.NewDiffServiceClient(conn), conn
}