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
92
|
package protoregistry_test
import (
"errors"
"fmt"
"testing"
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/praefect/protoregistry"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
func TestProtoRegistryTargetRepo(t *testing.T) {
r := protoregistry.New()
require.NoError(t, r.RegisterFiles(protoregistry.GitalyProtoFileDescriptors...))
testRepos := []*gitalypb.Repository{
&gitalypb.Repository{
GitAlternateObjectDirectories: []string{"a", "b", "c"},
GitObjectDirectory: "d",
GlProjectPath: "e",
GlRepository: "f",
RelativePath: "g",
StorageName: "h",
},
&gitalypb.Repository{
GitAlternateObjectDirectories: []string{"1", "2", "3"},
GitObjectDirectory: "4",
GlProjectPath: "5",
GlRepository: "6",
RelativePath: "7",
StorageName: "8",
},
}
testcases := []struct {
desc string
svc string
method string
pbMsg proto.Message
expectRepo *gitalypb.Repository
expectErr error
}{
{
desc: "valid request type single depth",
svc: "RepositoryService",
method: "RepackIncremental",
pbMsg: &gitalypb.RepackIncrementalRequest{
Repository: testRepos[0],
},
expectRepo: testRepos[0],
},
{
desc: "incorrect request type",
svc: "RepositoryService",
method: "RepackIncremental",
pbMsg: &gitalypb.RepackIncrementalResponse{},
expectErr: errors.New("proto message gitaly.RepackIncrementalResponse does not match expected RPC request message gitaly.RepackIncrementalRequest"),
},
{
desc: "target nested in oneOf",
svc: "OperationService",
method: "UserCommitFiles",
pbMsg: &gitalypb.UserCommitFilesRequest{
UserCommitFilesRequestPayload: &gitalypb.UserCommitFilesRequest_Header{
Header: &gitalypb.UserCommitFilesRequestHeader{
Repository: testRepos[1],
},
},
},
expectRepo: testRepos[1],
},
}
for _, tc := range testcases {
desc := fmt.Sprintf("%s:%s %s", tc.svc, tc.method, tc.desc)
t.Run(desc, func(t *testing.T) {
info, err := r.LookupMethod(fmt.Sprintf("/gitaly.%s/%s", tc.svc, tc.method))
require.NoError(t, err)
actualTarget, actualErr := info.TargetRepo(tc.pbMsg)
require.Equal(t, tc.expectErr, actualErr)
// not only do we want the value to be the same, but we actually want the
// exact same instance to be returned
if tc.expectRepo != actualTarget {
t.Fatal("pointers do not match")
}
})
}
}
|