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:
authorPatrick Bajao <ebajao@gitlab.com>2019-02-28 08:56:00 +0300
committerPatrick Bajao <ebajao@gitlab.com>2019-03-01 03:46:49 +0300
commit97a7c7f9877f29c2cd89864cbaa6e4c2f5714093 (patch)
tree2be204404347eb6b865f7a07780dac0dac18578b
parent702aecfba773b99beb6b154c039d84020c902a4d (diff)
Refactor test to be clearer
This include some refactoring for headerRequest() to make startBranchName, startRepository, and Force optional.
-rw-r--r--internal/service/operations/commit_files_test.go53
1 files changed, 25 insertions, 28 deletions
diff --git a/internal/service/operations/commit_files_test.go b/internal/service/operations/commit_files_test.go
index 50d02ede6..7c9a32de6 100644
--- a/internal/service/operations/commit_files_test.go
+++ b/internal/service/operations/commit_files_test.go
@@ -214,40 +214,37 @@ func TestSuccessfulUserCommitFilesRequestForceCommit(t *testing.T) {
ctxOuter, cancel := testhelper.Context()
defer cancel()
- branchName := "feature"
+ md := testhelper.GitalyServersMetadata(t, serverSocketPath)
+ ctx := metadata.NewOutgoingContext(ctxOuter, md)
authorName := []byte("Jane Doe")
authorEmail := []byte("janedoe@gitlab.com")
+ targetBranchName := "feature"
startBranchName := []byte("master")
- filePath := "TEST.md"
- md := testhelper.GitalyServersMetadata(t, serverSocketPath)
- ctx := metadata.NewOutgoingContext(ctxOuter, md)
- headerRequest := headerRequest(testRepo, user, branchName, commitFilesMessage, authorName, authorEmail, startBranchName, nil, true)
- actionsRequest1 := createFileHeaderRequest(filePath)
- actionsRequest2 := actionContentRequest("Test")
+ startBranchCommit, err := log.GetCommit(ctxOuter, testRepo, string(startBranchName))
+ require.NoError(t, err)
- t.Run("existing repo and branch starting from another branch", func(t *testing.T) {
- startBranchHeadCommit, err := log.GetCommit(ctxOuter, testRepo, string(startBranchName))
- require.NoError(t, err)
+ targetBranchCommit, err := log.GetCommit(ctxOuter, testRepo, targetBranchName)
+ require.NoError(t, err)
+ require.NotContains(t, targetBranchCommit.ParentIds, startBranchCommit.Id)
- oldHeadCommit, err := log.GetCommit(ctxOuter, testRepo, branchName)
- require.NoError(t, err)
-
- stream, err := client.UserCommitFiles(ctx)
- require.NoError(t, err)
- require.NoError(t, stream.Send(headerRequest))
- require.NoError(t, stream.Send(actionsRequest1))
- require.NoError(t, stream.Send(actionsRequest2))
-
- r, err := stream.CloseAndRecv()
- require.NoError(t, err)
- require.NotNil(t, r.GetBranchUpdate())
-
- headCommit, err := log.GetCommit(ctxOuter, testRepo, branchName)
- require.NoError(t, err)
- require.NotEqual(t, oldHeadCommit.Id, headCommit.Id)
- require.Contains(t, headCommit.ParentIds, startBranchHeadCommit.Id)
- })
+ headerRequest := headerRequest(testRepo, user, targetBranchName, commitFilesMessage, authorName, authorEmail)
+ header := headerRequest.UserCommitFilesRequestPayload.(*gitalypb.UserCommitFilesRequest_Header).Header
+ header.StartBranchName = startBranchName
+ header.Force = true
+ stream, err := client.UserCommitFiles(ctx)
+ require.NoError(t, err)
+ require.NoError(t, stream.Send(headerRequest))
+ require.NoError(t, stream.Send(createFileHeaderRequest("TEST.md")))
+ require.NoError(t, stream.Send(actionContentRequest("Test")))
+
+ r, err := stream.CloseAndRecv()
+ require.NoError(t, err)
+
+ update := r.GetBranchUpdate()
+ newCommit, err := log.GetCommit(ctxOuter, testRepo, update.CommitId)
+ require.NoError(t, err)
+ require.Equal(t, newCommit.ParentIds, []string{startBranchCommit.Id})
}
func TestFailedUserCommitFilesRequestDueToHooks(t *testing.T) {