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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
package testserver
import (
"net"
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
internalauth "gitlab.com/gitlab-org/gitaly/internal/gitaly/config/auth"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/server/auth"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/service/commit"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/service/internalgitaly"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/service/repository"
gitalyserver "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/server"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc"
"google.golang.org/grpc/health"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
)
var RubyServer = &rubyserver.Server{}
// PartialGitaly is a subset of Gitaly's behavior
type PartialGitaly interface {
gitalypb.ServerServiceServer
gitalypb.RepositoryServiceServer
gitalypb.InternalGitalyServer
gitalypb.CommitServiceServer
healthpb.HealthServer
}
func registerGitalyServices(server *grpc.Server, pg PartialGitaly) {
gitalypb.RegisterServerServiceServer(server, pg)
gitalypb.RegisterRepositoryServiceServer(server, pg)
gitalypb.RegisterInternalGitalyServer(server, pg)
gitalypb.RegisterCommitServiceServer(server, pg)
healthpb.RegisterHealthServer(server, pg)
}
// RealGitaly instantiates an instance of PartialGitaly that uses the real world
// services. This is intended to be used in integration tests to validate
// Gitaly services.
func RealGitaly(storages []config.Storage, authToken, internalSocketPath string) PartialGitaly {
return struct {
gitalypb.ServerServiceServer
gitalypb.RepositoryServiceServer
gitalypb.InternalGitalyServer
gitalypb.CommitServiceServer
healthpb.HealthServer
}{
gitalyserver.NewServer(storages),
repository.NewServer(config.Config, RubyServer, config.NewLocator(config.Config)),
internalgitaly.NewServer(config.Config.Storages),
commit.NewServer(config.Config, config.NewLocator(config.Config)),
health.NewServer(),
}
}
func RunInternalGitalyServer(t testing.TB, internalSocketPath string, storages []config.Storage, token string) (*grpc.Server, string, func()) {
streamInt := []grpc.StreamServerInterceptor{auth.StreamServerInterceptor(internalauth.Config{Token: token})}
unaryInt := []grpc.UnaryServerInterceptor{auth.UnaryServerInterceptor(internalauth.Config{Token: token})}
server := testhelper.NewTestGrpcServer(t, streamInt, unaryInt)
serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
listener, err := net.Listen("unix", serverSocketPath)
require.NoError(t, err)
internalListener, err := net.Listen("unix", internalSocketPath)
require.NoError(t, err)
registerGitalyServices(server, RealGitaly(storages, token, internalSocketPath))
errQ := make(chan error)
go func() { errQ <- server.Serve(listener) }()
go func() { errQ <- server.Serve(internalListener) }()
cleanup := func() {
server.Stop()
require.NoError(t, <-errQ)
require.NoError(t, <-errQ)
}
return server, "unix://" + serverSocketPath, cleanup
}
|