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 Steinhardt <psteinhardt@gitlab.com>2022-12-21 10:36:54 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2023-01-09 10:07:41 +0300
commit23277d0552961087bd259f9b469d79a94c859e13 (patch)
tree04009243fa5fec9122e1acdd755297ccf537d630
parentfaa85e577ef9dd8063e7a1096d04e68dd22da3fc (diff)
cmd/gitaly-ssh: Simplify test setup to use `testserver` package
One of the tests for git-upload-pack(1) in our gitaly-ssh command is manually assembling a test server. There is no reason to do this though. Refactor the code to use the `testserver` package instead.
-rw-r--r--cmd/gitaly-ssh/auth_test.go53
-rw-r--r--cmd/gitaly-ssh/upload_pack_test.go15
2 files changed, 7 insertions, 61 deletions
diff --git a/cmd/gitaly-ssh/auth_test.go b/cmd/gitaly-ssh/auth_test.go
index db33fbab3..5e6b9e6f8 100644
--- a/cmd/gitaly-ssh/auth_test.go
+++ b/cmd/gitaly-ssh/auth_test.go
@@ -4,26 +4,15 @@ package main
import (
"fmt"
- "net"
"os"
"path/filepath"
- "strconv"
"strings"
"testing"
"github.com/stretchr/testify/require"
- "gitlab.com/gitlab-org/gitaly/v15/client"
- "gitlab.com/gitlab-org/gitaly/v15/internal/backchannel"
- "gitlab.com/gitlab-org/gitaly/v15/internal/cache"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config"
- "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/hook"
- "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/server"
- "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service/setup"
- "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/transaction"
- "gitlab.com/gitlab-org/gitaly/v15/internal/gitlab"
- "gitlab.com/gitlab-org/gitaly/v15/internal/middleware/limithandler"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testcfg"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testserver"
@@ -141,45 +130,3 @@ func TestConnectivity(t *testing.T) {
})
}
}
-
-func runServer(t *testing.T, secure bool, cfg config.Cfg, connectionType string, addr string) (int, func()) {
- conns := client.NewPool()
- locator := config.NewLocator(cfg)
- registry := backchannel.NewRegistry()
- txManager := transaction.NewManager(cfg, registry)
- gitCmdFactory := gittest.NewCommandFactory(t, cfg)
- hookManager := hook.NewManager(cfg, locator, gitCmdFactory, txManager, gitlab.NewMockClient(
- t, gitlab.MockAllowed, gitlab.MockPreReceive, gitlab.MockPostReceive,
- ))
- limitHandler := limithandler.New(cfg, limithandler.LimitConcurrencyByRepo, limithandler.WithConcurrencyLimiters)
- diskCache := cache.New(cfg, locator)
- srv, err := server.New(secure, cfg, testhelper.NewDiscardingLogEntry(t), registry, diskCache, []*limithandler.LimiterMiddleware{limitHandler})
- require.NoError(t, err)
- setup.RegisterAll(srv, &service.Dependencies{
- Cfg: cfg,
- GitalyHookManager: hookManager,
- TransactionManager: txManager,
- StorageLocator: locator,
- ClientPool: conns,
- GitCmdFactory: gitCmdFactory,
- })
-
- listener, err := net.Listen(connectionType, addr)
- require.NoError(t, err)
-
- go testhelper.MustServe(t, srv, listener)
-
- port := 0
- if connectionType != "unix" {
- addrSplit := strings.Split(listener.Addr().String(), ":")
- portString := addrSplit[len(addrSplit)-1]
-
- port, err = strconv.Atoi(portString)
- require.NoError(t, err)
- }
-
- return port, func() {
- conns.Close()
- srv.Stop()
- }
-}
diff --git a/cmd/gitaly-ssh/upload_pack_test.go b/cmd/gitaly-ssh/upload_pack_test.go
index 844e000b1..efcf881d5 100644
--- a/cmd/gitaly-ssh/upload_pack_test.go
+++ b/cmd/gitaly-ssh/upload_pack_test.go
@@ -5,6 +5,7 @@ package main
import (
"fmt"
"os"
+ "strings"
"testing"
"github.com/stretchr/testify/require"
@@ -12,8 +13,10 @@ import (
"gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/updateref"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service/setup"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testcfg"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testserver"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/protobuf/encoding/protojson"
)
@@ -21,19 +24,15 @@ import (
const keepAroundNamespace = "refs/keep-around"
func TestVisibilityOfHiddenRefs(t *testing.T) {
+ t.Parallel()
+
ctx := testhelper.Context(t)
cfg, repo, repoPath := testcfg.BuildWithRepo(t)
testcfg.BuildGitalySSH(t, cfg)
testcfg.BuildGitalyHooks(t, cfg)
- socketPath := testhelper.GetTemporaryGitalySocketFileName(t)
-
- _, clean := runServer(t, false, cfg, "unix", socketPath)
- defer clean()
-
- _, clean = runServer(t, false, cfg, "unix", cfg.InternalSocketPath())
- defer clean()
+ address := testserver.RunGitalyServer(t, cfg, nil, setup.RegisterAll, testserver.WithDisablePraefect())
// Create a keep-around ref
existingSha := git.ObjectID("1e292f8fedd741b75372e19097c76d327140c312")
@@ -84,7 +83,7 @@ func TestVisibilityOfHiddenRefs(t *testing.T) {
stdout := gittest.ExecOpts(t, cfg, gittest.ExecConfig{
Env: []string{
fmt.Sprintf("GITALY_PAYLOAD=%s", payload),
- fmt.Sprintf("GITALY_ADDRESS=unix:%s", socketPath),
+ fmt.Sprintf("GITALY_ADDRESS=unix:%s", strings.TrimPrefix(address, "unix://")),
fmt.Sprintf("GITALY_WD=%s", wd),
fmt.Sprintf("PATH=.:%s", os.Getenv("PATH")),
fmt.Sprintf("GIT_SSH_COMMAND=%s upload-pack", cfg.BinaryPath("gitaly-ssh")),