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:
Diffstat (limited to 'internal/gitaly/service/operations/branches_test.go')
-rw-r--r--internal/gitaly/service/operations/branches_test.go361
1 files changed, 181 insertions, 180 deletions
diff --git a/internal/gitaly/service/operations/branches_test.go b/internal/gitaly/service/operations/branches_test.go
index 21bbef250..76c2394c6 100644
--- a/internal/gitaly/service/operations/branches_test.go
+++ b/internal/gitaly/service/operations/branches_test.go
@@ -16,10 +16,10 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/gitaly/service/hook"
"gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
- "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg"
"gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver"
+ "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
@@ -44,7 +44,7 @@ func TestSuccessfulCreateBranchRequest(t *testing.T) {
ctx, cfg, repoProto, repoPath, client := setupOperationsService(t, ctx)
- repo := localrepo.New(git.NewExecCommandFactory(cfg), repoProto, cfg)
+ repo := localrepo.NewTestRepo(t, cfg, repoProto)
startPoint := "c7fbe50c7c7419d9701eebe64b1fdacc3df5b9dd"
startPointCommit, err := repo.ReadCommit(ctx, git.Revision(startPoint))
@@ -97,117 +97,119 @@ func TestSuccessfulCreateBranchRequest(t *testing.T) {
Repository: repoProto,
BranchName: []byte(branchName),
StartPoint: []byte(testCase.startPoint),
- User: testhelper.TestUser,
+ User: gittest.TestUser,
}
response, err := client.UserCreateBranch(ctx, request)
if testCase.expectedBranch != nil {
- defer testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", "-D", branchName)
+ defer gittest.Exec(t, cfg, "-C", repoPath, "branch", "-D", branchName)
}
require.NoError(t, err)
require.Equal(t, testCase.expectedBranch, response.Branch)
require.Empty(t, response.PreReceiveError)
- branches := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "for-each-ref", "--", "refs/heads/"+branchName)
+ branches := gittest.Exec(t, cfg, "-C", repoPath, "for-each-ref", "--", "refs/heads/"+branchName)
require.Contains(t, string(branches), "refs/heads/"+branchName)
})
}
}
func TestUserCreateBranchWithTransaction(t *testing.T) {
- testhelper.NewFeatureSets([]featureflag.FeatureFlag{
- featureflag.BackchannelVoting,
- }).Run(t, func(t *testing.T, ctx context.Context) {
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
-
- transactionServer := &testTransactionServer{}
+ cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+
+ transactionServer := &testTransactionServer{}
+
+ cfg.ListenAddr = "127.0.0.1:0" // runs gitaly on the TCP address
+ addr := testserver.RunGitalyServer(t, cfg, nil, func(srv *grpc.Server, deps *service.Dependencies) {
+ gitalypb.RegisterOperationServiceServer(srv, NewServer(
+ deps.GetCfg(),
+ nil,
+ deps.GetHookManager(),
+ deps.GetLocator(),
+ deps.GetConnsPool(),
+ deps.GetGitCmdFactory(),
+ deps.GetCatfileCache(),
+ ))
+ gitalypb.RegisterHookServiceServer(srv, hook.NewServer(deps.GetCfg(), deps.GetHookManager(), deps.GetGitCmdFactory()))
+ // Praefect proxy execution disabled as praefect runs only on the UNIX socket, but
+ // the test requires a TCP listening address.
+ }, testserver.WithDisablePraefect())
+
+ addrConfig, err := starter.ParseEndpoint(addr)
+ require.NoError(t, err)
+ _, port, err := net.SplitHostPort(addrConfig.Addr)
+ require.NoError(t, err)
- cfg.ListenAddr = "127.0.0.1:0" // runs gitaly on the TCP address
- addr := testserver.RunGitalyServer(t, cfg, nil, func(srv *grpc.Server, deps *service.Dependencies) {
- gitalypb.RegisterOperationServiceServer(srv, NewServer(deps.GetCfg(), nil, deps.GetHookManager(), deps.GetLocator(), deps.GetConnsPool(), deps.GetGitCmdFactory()))
- gitalypb.RegisterHookServiceServer(srv, hook.NewServer(deps.GetCfg(), deps.GetHookManager(), deps.GetGitCmdFactory()))
- if featureflag.IsDisabled(ctx, featureflag.BackchannelVoting) {
- gitalypb.RegisterRefTransactionServer(srv, transactionServer)
- }
- // Praefect proxy execution disabled as praefect runs only on the UNIX socket, but
- // the test requires a TCP listening address.
- }, testserver.WithDisablePraefect())
-
- addrConfig, err := starter.ParseEndpoint(addr)
- require.NoError(t, err)
- _, port, err := net.SplitHostPort(addrConfig.Addr)
- require.NoError(t, err)
-
- testcases := []struct {
- desc string
- address string
- server metadata.PraefectServer
- }{
- {
- desc: "explicit TCP address",
- address: addr,
- server: metadata.PraefectServer{
- ListenAddr: addr,
- Token: cfg.Auth.Token,
- },
+ testcases := []struct {
+ desc string
+ address string
+ server txinfo.PraefectServer
+ }{
+ {
+ desc: "explicit TCP address",
+ address: addr,
+ server: txinfo.PraefectServer{
+ ListenAddr: addr,
+ Token: cfg.Auth.Token,
},
- {
- desc: "catch-all TCP address",
- address: addr,
- server: metadata.PraefectServer{
- ListenAddr: "tcp://0.0.0.0:" + port,
- Token: cfg.Auth.Token,
- },
+ },
+ {
+ desc: "catch-all TCP address",
+ address: addr,
+ server: txinfo.PraefectServer{
+ ListenAddr: "tcp://0.0.0.0:" + port,
+ Token: cfg.Auth.Token,
},
- {
- desc: "Unix socket",
- address: "unix://" + cfg.GitalyInternalSocketPath(),
- server: metadata.PraefectServer{
- SocketPath: "unix://" + cfg.GitalyInternalSocketPath(),
- Token: cfg.Auth.Token,
- },
+ },
+ {
+ desc: "Unix socket",
+ address: "unix://" + cfg.GitalyInternalSocketPath(),
+ server: txinfo.PraefectServer{
+ SocketPath: "unix://" + cfg.GitalyInternalSocketPath(),
+ Token: cfg.Auth.Token,
},
- }
+ },
+ }
- for _, tc := range testcases {
- t.Run(tc.desc, func(t *testing.T) {
- defer testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", "-D", "new-branch")
-
- client := newMuxedOperationClient(t, ctx, tc.address, cfg.Auth.Token,
- backchannel.NewClientHandshaker(
- testhelper.DiscardTestEntry(t),
- func() backchannel.Server {
- srv := grpc.NewServer()
- if featureflag.IsEnabled(ctx, featureflag.BackchannelVoting) {
- gitalypb.RegisterRefTransactionServer(srv, transactionServer)
- }
- return srv
- },
- ),
- )
-
- ctx, err := tc.server.Inject(ctx)
- require.NoError(t, err)
- ctx, err = metadata.InjectTransaction(ctx, 1, "node", true)
- require.NoError(t, err)
- ctx = helper.IncomingToOutgoing(ctx)
+ for _, tc := range testcases {
+ t.Run(tc.desc, func(t *testing.T) {
+ defer gittest.Exec(t, cfg, "-C", repoPath, "branch", "-D", "new-branch")
- request := &gitalypb.UserCreateBranchRequest{
- Repository: repo,
- BranchName: []byte("new-branch"),
- StartPoint: []byte("c7fbe50c7c7419d9701eebe64b1fdacc3df5b9dd"),
- User: testhelper.TestUser,
- }
+ ctx, cancel := testhelper.Context()
+ defer cancel()
- transactionServer.called = 0
- response, err := client.UserCreateBranch(ctx, request)
- require.NoError(t, err)
- require.Empty(t, response.PreReceiveError)
- require.Equal(t, 1, transactionServer.called)
- })
- }
- })
+ client := newMuxedOperationClient(t, ctx, tc.address, cfg.Auth.Token,
+ backchannel.NewClientHandshaker(
+ testhelper.DiscardTestEntry(t),
+ func() backchannel.Server {
+ srv := grpc.NewServer()
+ gitalypb.RegisterRefTransactionServer(srv, transactionServer)
+ return srv
+ },
+ ),
+ )
+
+ ctx, err := tc.server.Inject(ctx)
+ require.NoError(t, err)
+ ctx, err = txinfo.InjectTransaction(ctx, 1, "node", true)
+ require.NoError(t, err)
+ ctx = helper.IncomingToOutgoing(ctx)
+
+ request := &gitalypb.UserCreateBranchRequest{
+ Repository: repo,
+ BranchName: []byte("new-branch"),
+ StartPoint: []byte("c7fbe50c7c7419d9701eebe64b1fdacc3df5b9dd"),
+ User: gittest.TestUser,
+ }
+
+ transactionServer.called = 0
+ response, err := client.UserCreateBranch(ctx, request)
+ require.NoError(t, err)
+ require.Empty(t, response.PreReceiveError)
+ require.Equal(t, 2, transactionServer.called)
+ })
+ }
}
func TestSuccessfulGitHooksForUserCreateBranchRequest(t *testing.T) {
@@ -217,19 +219,19 @@ func TestSuccessfulGitHooksForUserCreateBranchRequest(t *testing.T) {
}
func testSuccessfulGitHooksForUserCreateBranchRequest(t *testing.T, ctx context.Context) {
- ctx, _, repo, repoPath, client := setupOperationsService(t, ctx)
+ ctx, cfg, repo, repoPath, client := setupOperationsService(t, ctx)
branchName := "new-branch"
request := &gitalypb.UserCreateBranchRequest{
Repository: repo,
BranchName: []byte(branchName),
StartPoint: []byte("c7fbe50c7c7419d9701eebe64b1fdacc3df5b9dd"),
- User: testhelper.TestUser,
+ User: gittest.TestUser,
}
for _, hookName := range GitlabHooks {
t.Run(hookName, func(t *testing.T) {
- defer testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", "-D", branchName)
+ defer gittest.Exec(t, cfg, "-C", repoPath, "branch", "-D", branchName)
hookOutputTempPath := gittest.WriteEnvToCustomHook(t, repoPath, hookName)
@@ -238,7 +240,7 @@ func testSuccessfulGitHooksForUserCreateBranchRequest(t *testing.T, ctx context.
require.Empty(t, response.PreReceiveError)
output := string(testhelper.MustReadFile(t, hookOutputTempPath))
- require.Contains(t, output, "GL_USERNAME="+testhelper.TestUser.GlUsername)
+ require.Contains(t, output, "GL_USERNAME="+gittest.TestUser.GlUsername)
})
}
}
@@ -249,7 +251,7 @@ func TestSuccessfulCreateBranchRequestWithStartPointRefPrefix(t *testing.T) {
ctx, cfg, repoProto, repoPath, client := setupOperationsService(t, ctx)
- repo := localrepo.New(git.NewExecCommandFactory(cfg), repoProto, cfg)
+ repo := localrepo.NewTestRepo(t, cfg, repoProto)
testCases := []struct {
desc string
@@ -268,20 +270,20 @@ func TestSuccessfulCreateBranchRequestWithStartPointRefPrefix(t *testing.T) {
branchName: "topic",
startPoint: "heads/master",
startPointCommit: "9a944d90955aaf45f6d0c88f30e27f8d2c41cec0", // TODO: see below
- user: testhelper.TestUser,
+ user: gittest.TestUser,
},
{
desc: "the StartPoint parameter does DWYM references (boo!) 2",
branchName: "topic2",
startPoint: "refs/heads/master",
startPointCommit: "c642fe9b8b9f28f9225d7ea953fe14e74748d53b", // TODO: see below
- user: testhelper.TestUser,
+ user: gittest.TestUser,
},
}
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
- testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "update-ref", "refs/heads/"+testCase.startPoint,
+ gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/heads/"+testCase.startPoint,
testCase.startPointCommit,
git.ZeroOID.String(),
)
@@ -310,7 +312,7 @@ func TestSuccessfulCreateBranchRequestWithStartPointRefPrefix(t *testing.T) {
},
}
require.Equal(t, responseOk, response)
- branches := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "for-each-ref", "--", "refs/heads/"+testCase.branchName)
+ branches := gittest.Exec(t, cfg, "-C", repoPath, "for-each-ref", "--", "refs/heads/"+testCase.branchName)
require.Contains(t, string(branches), "refs/heads/"+testCase.branchName)
})
}
@@ -326,7 +328,7 @@ func TestFailedUserCreateBranchDueToHooks(t *testing.T) {
Repository: repo,
BranchName: []byte("new-branch"),
StartPoint: []byte("c7fbe50c7c7419d9701eebe64b1fdacc3df5b9dd"),
- User: testhelper.TestUser,
+ User: gittest.TestUser,
}
// Write a hook that will fail with the environment as the error message
// so we can check that string for our env variables.
@@ -337,7 +339,7 @@ func TestFailedUserCreateBranchDueToHooks(t *testing.T) {
response, err := client.UserCreateBranch(ctx, request)
require.Nil(t, err)
- require.Contains(t, response.PreReceiveError, "GL_USERNAME="+testhelper.TestUser.GlUsername)
+ require.Contains(t, response.PreReceiveError, "GL_USERNAME="+gittest.TestUser.GlUsername)
}
}
@@ -358,7 +360,7 @@ func TestFailedUserCreateBranchRequest(t *testing.T) {
desc: "empty start_point",
branchName: "shiny-new-branch",
startPoint: "",
- user: testhelper.TestUser,
+ user: gittest.TestUser,
err: status.Error(codes.InvalidArgument, "empty start point"),
},
{
@@ -372,7 +374,7 @@ func TestFailedUserCreateBranchRequest(t *testing.T) {
desc: "non-existing starting point",
branchName: "new-branch",
startPoint: "i-dont-exist",
- user: testhelper.TestUser,
+ user: gittest.TestUser,
err: status.Errorf(codes.FailedPrecondition, "revspec '%s' not found", "i-dont-exist"),
},
@@ -380,7 +382,7 @@ func TestFailedUserCreateBranchRequest(t *testing.T) {
desc: "branch exists",
branchName: "master",
startPoint: "master",
- user: testhelper.TestUser,
+ user: gittest.TestUser,
err: status.Errorf(codes.FailedPrecondition, "Could not update %s. Please refresh and try again.", "master"),
},
}
@@ -408,7 +410,7 @@ func TestSuccessfulUserDeleteBranchRequest(t *testing.T) {
}
func testSuccessfulUserDeleteBranchRequest(t *testing.T, ctx context.Context) {
- ctx, _, repo, repoPath, client := setupOperationsService(t, ctx)
+ ctx, cfg, repo, repoPath, client := setupOperationsService(t, ctx)
testCases := []struct {
desc string
@@ -422,28 +424,28 @@ func testSuccessfulUserDeleteBranchRequest(t *testing.T, ctx context.Context) {
desc: "simple successful deletion",
branchNameInput: "to-attempt-to-delete-soon-branch",
branchCommit: "c7fbe50c7c7419d9701eebe64b1fdacc3df5b9dd",
- user: testhelper.TestUser,
+ user: gittest.TestUser,
response: &gitalypb.UserDeleteBranchResponse{},
},
{
desc: "partially prefixed successful deletion",
branchNameInput: "heads/to-attempt-to-delete-soon-branch",
branchCommit: "9a944d90955aaf45f6d0c88f30e27f8d2c41cec0",
- user: testhelper.TestUser,
+ user: gittest.TestUser,
response: &gitalypb.UserDeleteBranchResponse{},
},
{
desc: "branch with refs/heads/ prefix",
branchNameInput: "refs/heads/branch",
branchCommit: "9a944d90955aaf45f6d0c88f30e27f8d2c41cec0",
- user: testhelper.TestUser,
+ user: gittest.TestUser,
response: &gitalypb.UserDeleteBranchResponse{},
},
}
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
- testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", testCase.branchNameInput, testCase.branchCommit)
+ gittest.Exec(t, cfg, "-C", repoPath, "branch", testCase.branchNameInput, testCase.branchCommit)
response, err := client.UserDeleteBranch(ctx, &gitalypb.UserDeleteBranchRequest{
Repository: repo,
@@ -453,7 +455,7 @@ func testSuccessfulUserDeleteBranchRequest(t *testing.T, ctx context.Context) {
require.NoError(t, err)
testhelper.ProtoEqual(t, testCase.response, response)
- refs := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "for-each-ref", "--", "refs/heads/"+testCase.branchNameInput)
+ refs := gittest.Exec(t, cfg, "-C", repoPath, "for-each-ref", "--", "refs/heads/"+testCase.branchNameInput)
require.NotContains(t, string(refs), testCase.branchCommit, "branch deleted from refs")
})
}
@@ -463,19 +465,19 @@ func TestSuccessfulGitHooksForUserDeleteBranchRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- ctx, _, repo, repoPath, client := setupOperationsService(t, ctx)
+ ctx, cfg, repo, repoPath, client := setupOperationsService(t, ctx)
branchNameInput := "to-be-deleted-soon-branch"
request := &gitalypb.UserDeleteBranchRequest{
Repository: repo,
BranchName: []byte(branchNameInput),
- User: testhelper.TestUser,
+ User: gittest.TestUser,
}
for _, hookName := range GitlabHooks {
t.Run(hookName, func(t *testing.T) {
- testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", branchNameInput)
+ gittest.Exec(t, cfg, "-C", repoPath, "branch", branchNameInput)
hookOutputTempPath := gittest.WriteEnvToCustomHook(t, repoPath, hookName)
@@ -483,70 +485,69 @@ func TestSuccessfulGitHooksForUserDeleteBranchRequest(t *testing.T) {
require.NoError(t, err)
output := testhelper.MustReadFile(t, hookOutputTempPath)
- require.Contains(t, string(output), "GL_USERNAME="+testhelper.TestUser.GlUsername)
+ require.Contains(t, string(output), "GL_USERNAME="+gittest.TestUser.GlUsername)
})
}
}
func TestUserDeleteBranch_transaction(t *testing.T) {
- testhelper.NewFeatureSets([]featureflag.FeatureFlag{
- featureflag.BackchannelVoting,
- }).Run(t, func(t *testing.T, ctx context.Context) {
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
-
- // This creates a new branch "delete-me" which exists both in the packed-refs file and as a
- // loose reference. Git will create two reference transactions for this: one transaction to
- // delete the packed-refs reference, and one to delete the loose ref. But given that we want
- // to be independent of how well-packed refs are, we expect to get a single transactional
- // vote, only.
- testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "update-ref", "refs/heads/delete-me", "master~")
- testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "pack-refs", "--all")
- testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "update-ref", "refs/heads/delete-me", "master")
-
- transactionServer := &testTransactionServer{}
-
- testserver.RunGitalyServer(t, cfg, nil, func(srv *grpc.Server, deps *service.Dependencies) {
- gitalypb.RegisterOperationServiceServer(srv, NewServer(deps.GetCfg(), nil, deps.GetHookManager(), deps.GetLocator(), deps.GetConnsPool(), deps.GetGitCmdFactory()))
- // We're setting up the RefTransaction server on the same server as the OperationService.
- // Typically it would be hosted on Praefect, but in order to make the already-complex test
- // setup not even more complex we just reuse the same GRPC server.
- if featureflag.IsDisabled(ctx, featureflag.BackchannelVoting) {
- gitalypb.RegisterRefTransactionServer(srv, transactionServer)
- }
- })
+ cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+
+ // This creates a new branch "delete-me" which exists both in the packed-refs file and as a
+ // loose reference. Git will create two reference transactions for this: one transaction to
+ // delete the packed-refs reference, and one to delete the loose ref. But given that we want
+ // to be independent of how well-packed refs are, we expect to get a single transactional
+ // vote, only.
+ gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/heads/delete-me", "master~")
+ gittest.Exec(t, cfg, "-C", repoPath, "pack-refs", "--all")
+ gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/heads/delete-me", "master")
+
+ transactionServer := &testTransactionServer{}
+
+ testserver.RunGitalyServer(t, cfg, nil, func(srv *grpc.Server, deps *service.Dependencies) {
+ gitalypb.RegisterOperationServiceServer(srv, NewServer(
+ deps.GetCfg(),
+ nil,
+ deps.GetHookManager(),
+ deps.GetLocator(),
+ deps.GetConnsPool(),
+ deps.GetGitCmdFactory(),
+ deps.GetCatfileCache(),
+ ))
+ })
- praefect := metadata.PraefectServer{
- SocketPath: fmt.Sprintf("unix://" + cfg.GitalyInternalSocketPath()),
- Token: cfg.Auth.Token,
- }
+ praefect := txinfo.PraefectServer{
+ SocketPath: fmt.Sprintf("unix://" + cfg.GitalyInternalSocketPath()),
+ Token: cfg.Auth.Token,
+ }
- ctx, err := praefect.Inject(ctx)
- require.NoError(t, err)
- ctx, err = metadata.InjectTransaction(ctx, 1, "node", true)
- require.NoError(t, err)
- ctx = helper.IncomingToOutgoing(ctx)
-
- client := newMuxedOperationClient(t, ctx, fmt.Sprintf("unix://"+cfg.GitalyInternalSocketPath()), cfg.Auth.Token,
- backchannel.NewClientHandshaker(
- testhelper.DiscardTestEntry(t),
- func() backchannel.Server {
- srv := grpc.NewServer()
- if featureflag.IsEnabled(ctx, featureflag.BackchannelVoting) {
- gitalypb.RegisterRefTransactionServer(srv, transactionServer)
- }
- return srv
- },
- ),
- )
+ ctx, cancel := testhelper.Context()
+ defer cancel()
- _, err = client.UserDeleteBranch(ctx, &gitalypb.UserDeleteBranchRequest{
- Repository: repo,
- BranchName: []byte("delete-me"),
- User: testhelper.TestUser,
- })
- require.NoError(t, err)
- require.Equal(t, 1, transactionServer.called)
+ ctx, err := praefect.Inject(ctx)
+ require.NoError(t, err)
+ ctx, err = txinfo.InjectTransaction(ctx, 1, "node", true)
+ require.NoError(t, err)
+ ctx = helper.IncomingToOutgoing(ctx)
+
+ client := newMuxedOperationClient(t, ctx, fmt.Sprintf("unix://"+cfg.GitalyInternalSocketPath()), cfg.Auth.Token,
+ backchannel.NewClientHandshaker(
+ testhelper.DiscardTestEntry(t),
+ func() backchannel.Server {
+ srv := grpc.NewServer()
+ gitalypb.RegisterRefTransactionServer(srv, transactionServer)
+ return srv
+ },
+ ),
+ )
+
+ _, err = client.UserDeleteBranch(ctx, &gitalypb.UserDeleteBranchRequest{
+ Repository: repo,
+ BranchName: []byte("delete-me"),
+ User: gittest.TestUser,
})
+ require.NoError(t, err)
+ require.Equal(t, 2, transactionServer.called)
}
func TestFailedUserDeleteBranchDueToValidation(t *testing.T) {
@@ -574,7 +575,7 @@ func TestFailedUserDeleteBranchDueToValidation(t *testing.T) {
desc: "empty branch name",
request: &gitalypb.UserDeleteBranchRequest{
Repository: repo,
- User: testhelper.TestUser,
+ User: gittest.TestUser,
},
response: nil,
err: status.Error(codes.InvalidArgument, "Bad Request (empty branch name)"),
@@ -583,7 +584,7 @@ func TestFailedUserDeleteBranchDueToValidation(t *testing.T) {
desc: "non-existent branch name",
request: &gitalypb.UserDeleteBranchRequest{
Repository: repo,
- User: testhelper.TestUser,
+ User: gittest.TestUser,
BranchName: []byte("i-do-not-exist"),
},
response: nil,
@@ -604,15 +605,15 @@ func TestFailedUserDeleteBranchDueToHooks(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- ctx, _, repo, repoPath, client := setupOperationsService(t, ctx)
+ ctx, cfg, repo, repoPath, client := setupOperationsService(t, ctx)
branchNameInput := "to-be-deleted-soon-branch"
- testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", branchNameInput)
+ gittest.Exec(t, cfg, "-C", repoPath, "branch", branchNameInput)
request := &gitalypb.UserDeleteBranchRequest{
Repository: repo,
BranchName: []byte(branchNameInput),
- User: testhelper.TestUser,
+ User: gittest.TestUser,
}
hookContent := []byte("#!/bin/sh\necho GL_ID=$GL_ID\nexit 1")
@@ -623,9 +624,9 @@ func TestFailedUserDeleteBranchDueToHooks(t *testing.T) {
response, err := client.UserDeleteBranch(ctx, request)
require.NoError(t, err)
- require.Contains(t, response.PreReceiveError, "GL_ID="+testhelper.TestUser.GlId)
+ require.Contains(t, response.PreReceiveError, "GL_ID="+gittest.TestUser.GlId)
- branches := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "for-each-ref", "--", "refs/heads/"+branchNameInput)
+ branches := gittest.Exec(t, cfg, "-C", repoPath, "for-each-ref", "--", "refs/heads/"+branchNameInput)
require.Contains(t, string(branches), branchNameInput, "branch name does not exist in branches list")
})
}
@@ -635,7 +636,7 @@ func TestBranchHookOutput(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- ctx, _, repo, repoPath, client := setupOperationsService(t, ctx)
+ ctx, cfg, repo, repoPath, client := setupOperationsService(t, ctx)
testCases := []struct {
desc string
@@ -682,12 +683,12 @@ func TestBranchHookOutput(t *testing.T) {
Repository: repo,
BranchName: []byte(branchNameInput),
StartPoint: []byte("master"),
- User: testhelper.TestUser,
+ User: gittest.TestUser,
}
deleteRequest := &gitalypb.UserDeleteBranchRequest{
Repository: repo,
BranchName: []byte(branchNameInput),
- User: testhelper.TestUser,
+ User: gittest.TestUser,
}
gittest.WriteCustomHook(t, repoPath, hookName, []byte(testCase.hookContent))
@@ -696,8 +697,8 @@ func TestBranchHookOutput(t *testing.T) {
require.NoError(t, err)
require.Equal(t, testCase.output, createResponse.PreReceiveError)
- testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", branchNameInput)
- defer testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", "-d", branchNameInput)
+ gittest.Exec(t, cfg, "-C", repoPath, "branch", branchNameInput)
+ defer gittest.Exec(t, cfg, "-C", repoPath, "branch", "-d", branchNameInput)
deleteResponse, err := client.UserDeleteBranch(ctx, deleteRequest)
require.NoError(t, err)