1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
package smarthttp
import (
"os"
"testing"
"github.com/stretchr/testify/require"
gitalyauth "gitlab.com/gitlab-org/gitaly/auth"
diskcache "gitlab.com/gitlab-org/gitaly/internal/cache"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/hook"
hookservice "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/hook"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/internal/middleware/cache"
"gitlab.com/gitlab-org/gitaly/internal/praefect/protoregistry"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc"
)
const (
pktFlushStr = "0000"
)
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
defer testhelper.MustHaveNoChildProcess()
cleanup := testhelper.Configure()
defer cleanup()
return m.Run()
}
func runSmartHTTPServer(t *testing.T, cfg config.Cfg, serverOpts ...ServerOpt) (string, func()) {
locator := config.NewLocator(cfg)
keyer := diskcache.NewLeaseKeyer(locator)
txManager := transaction.NewManager(cfg)
hookManager := hook.NewManager(locator, txManager, hook.GitlabAPIStub, cfg)
gitCmdFactory := git.NewExecCommandFactory(cfg)
srv := testhelper.NewServer(t,
[]grpc.StreamServerInterceptor{
cache.StreamInvalidator(keyer, protoregistry.GitalyProtoPreregistered),
},
[]grpc.UnaryServerInterceptor{
cache.UnaryInvalidator(keyer, protoregistry.GitalyProtoPreregistered),
},
testhelper.WithInternalSocket(cfg))
gitalypb.RegisterSmartHTTPServiceServer(srv.GrpcServer(), NewServer(cfg, locator, gitCmdFactory, serverOpts...))
gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hookservice.NewServer(cfg, hookManager, gitCmdFactory))
srv.Start(t)
return "unix://" + srv.Socket(), srv.Stop
}
func newSmartHTTPClient(t *testing.T, serverSocketPath, token string) (gitalypb.SmartHTTPServiceClient, *grpc.ClientConn) {
t.Helper()
connOpts := []grpc.DialOption{
grpc.WithInsecure(),
grpc.WithPerRPCCredentials(gitalyauth.RPCCredentialsV2(token)),
}
conn, err := grpc.Dial(serverSocketPath, connOpts...)
require.NoError(t, err)
return gitalypb.NewSmartHTTPServiceClient(conn), conn
}
|