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
89
90
91
|
package server
import (
"net"
"testing"
"time"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly-proto/go/gitalypb"
gitalyauth "gitlab.com/gitlab-org/gitaly/auth"
"gitlab.com/gitlab-org/gitaly/internal/config"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/server/auth"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/internal/version"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
func TestGitalyServerInfo(t *testing.T) {
server, serverSocketPath := runServer(t)
defer server.Stop()
client, conn := newServerClient(t, serverSocketPath)
defer conn.Close()
ctx, cancel := testhelper.Context()
defer cancel()
// Setup storage paths
testStorages := []config.Storage{
{Name: "default", Path: testhelper.GitlabTestStoragePath()},
{Name: "broken", Path: "/does/not/exist"},
}
defer func(oldStorages []config.Storage) {
config.Config.Storages = oldStorages
}(config.Config.Storages)
config.Config.Storages = testStorages
c, err := client.ServerInfo(ctx, &gitalypb.ServerInfoRequest{})
require.NoError(t, err)
require.Equal(t, version.GetVersion(), c.GetServerVersion())
gitVersion, err := git.Version()
require.NoError(t, err)
require.Equal(t, gitVersion, c.GetGitVersion())
require.Len(t, c.GetStorageStatuses(), len(testStorages))
require.True(t, c.GetStorageStatuses()[0].Readable)
require.True(t, c.GetStorageStatuses()[0].Writeable)
require.False(t, c.GetStorageStatuses()[1].Readable)
require.False(t, c.GetStorageStatuses()[1].Writeable)
}
func runServer(t *testing.T) (*grpc.Server, string) {
streamInt := []grpc.StreamServerInterceptor{auth.StreamServerInterceptor()}
unaryInt := []grpc.UnaryServerInterceptor{auth.UnaryServerInterceptor()}
server := testhelper.NewTestGrpcServer(t, streamInt, unaryInt)
serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
listener, err := net.Listen("unix", serverSocketPath)
if err != nil {
t.Fatal(err)
}
gitalypb.RegisterServerServiceServer(server, NewServer())
reflection.Register(server)
go server.Serve(listener)
return server, serverSocketPath
}
func newServerClient(t *testing.T, serverSocketPath string) (gitalypb.ServerServiceClient, *grpc.ClientConn) {
connOpts := []grpc.DialOption{
grpc.WithInsecure(),
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout)
}),
grpc.WithPerRPCCredentials(gitalyauth.RPCCredentials(testhelper.RepositoryAuthToken)),
}
conn, err := grpc.Dial(serverSocketPath, connOpts...)
if err != nil {
t.Fatal(err)
}
return gitalypb.NewServerServiceClient(conn), conn
}
|