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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
package commit
import (
"io"
"testing"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly-proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
)
func TestSuccessfulCommitsBetween(t *testing.T) {
server, serverSocketPath := startTestServices(t)
defer server.Stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
from := []byte("498214de67004b1da3d820901307bed2a68a8ef6") // branch-merged
to := []byte("ba3343bc4fa403a8dfbfcab7fc1a8c29ee34bd69") // spooky-stuff
fakeHash := []byte("f63f41fe459e62e1228fcef60d7189127aeba95a")
fakeRef := []byte("non-existing-ref")
expectedCommits := []*gitalypb.GitCommit{
{
Id: "b83d6e391c22777fca1ed3012fce84f633d7fed0",
Subject: []byte("Merge branch 'branch-merged' into 'master'"),
Body: []byte("Merge branch 'branch-merged' into 'master'\r\n\r\nadds bar folder and branch-test text file to check Repository merged_to_root_ref method\r\n\r\n\r\n\r\nSee merge request !12"),
Author: &gitalypb.CommitAuthor{
Name: []byte("Job van der Voort"),
Email: []byte("job@gitlab.com"),
Date: ×tamp.Timestamp{Seconds: 1474987066},
},
Committer: &gitalypb.CommitAuthor{
Name: []byte("Job van der Voort"),
Email: []byte("job@gitlab.com"),
Date: ×tamp.Timestamp{Seconds: 1474987066},
},
ParentIds: []string{
"1b12f15a11fc6e62177bef08f47bc7b5ce50b141",
"498214de67004b1da3d820901307bed2a68a8ef6",
},
BodySize: 162,
},
{
Id: "4a24d82dbca5c11c61556f3b35ca472b7463187e",
Subject: []byte("Update README.md to include `Usage in testing and development`"),
Body: []byte("Update README.md to include `Usage in testing and development`"),
Author: &gitalypb.CommitAuthor{
Name: []byte("Luke \"Jared\" Bennett"),
Email: []byte("lbennett@gitlab.com"),
Date: ×tamp.Timestamp{Seconds: 1491905339},
},
Committer: &gitalypb.CommitAuthor{
Name: []byte("Luke \"Jared\" Bennett"),
Email: []byte("lbennett@gitlab.com"),
Date: ×tamp.Timestamp{Seconds: 1491905339},
},
ParentIds: []string{"b83d6e391c22777fca1ed3012fce84f633d7fed0"},
BodySize: 62,
},
{
Id: "e63f41fe459e62e1228fcef60d7189127aeba95a",
Subject: []byte("Merge branch 'gitlab-test-usage-dev-testing-docs' into 'master'"),
Body: []byte("Merge branch 'gitlab-test-usage-dev-testing-docs' into 'master'\r\n\r\nUpdate README.md to include `Usage in testing and development`\r\n\r\nSee merge request !21"),
Author: &gitalypb.CommitAuthor{
Name: []byte("Sean McGivern"),
Email: []byte("sean@mcgivern.me.uk"),
Date: ×tamp.Timestamp{Seconds: 1491906794},
},
Committer: &gitalypb.CommitAuthor{
Name: []byte("Sean McGivern"),
Email: []byte("sean@mcgivern.me.uk"),
Date: ×tamp.Timestamp{Seconds: 1491906794},
},
ParentIds: []string{
"b83d6e391c22777fca1ed3012fce84f633d7fed0",
"4a24d82dbca5c11c61556f3b35ca472b7463187e",
},
BodySize: 154,
},
{
Id: "ba3343bc4fa403a8dfbfcab7fc1a8c29ee34bd69",
Subject: []byte("Weird commit date"),
Body: []byte("Weird commit date\n"),
Author: &gitalypb.CommitAuthor{
Name: []byte("Alejandro Rodríguez"),
Email: []byte("alejorro70@gmail.com"),
// Not the actual commit date, but the biggest we can represent
Date: ×tamp.Timestamp{Seconds: 9223371974719179007},
},
Committer: &gitalypb.CommitAuthor{
Name: []byte("Alejandro Rodríguez"),
Email: []byte("alejorro70@gmail.com"),
Date: ×tamp.Timestamp{Seconds: 9223371974719179007},
},
ParentIds: []string{"e63f41fe459e62e1228fcef60d7189127aeba95a"},
BodySize: 18,
},
}
testCases := []struct {
description string
from []byte
to []byte
expectedCommits []*gitalypb.GitCommit
}{
{
description: "From hash to hash",
from: from,
to: to,
expectedCommits: expectedCommits,
},
{
description: "From hash to ref",
from: from,
to: []byte("gitaly-test-ref"),
expectedCommits: expectedCommits,
},
{
description: "From ref to hash",
from: []byte("branch-merged"),
to: to,
expectedCommits: expectedCommits,
},
{
description: "From ref to ref",
from: []byte("branch-merged"),
to: []byte("gitaly-test-ref"),
expectedCommits: expectedCommits,
},
{
description: "To hash doesn't exist",
from: from,
to: fakeHash,
expectedCommits: []*gitalypb.GitCommit{},
},
{
description: "From hash doesn't exist",
from: fakeHash,
to: to,
expectedCommits: []*gitalypb.GitCommit{},
},
{
description: "To ref doesn't exist",
from: from,
to: fakeRef,
expectedCommits: []*gitalypb.GitCommit{},
},
{
description: "From ref doesn't exist",
from: fakeRef,
to: to,
expectedCommits: []*gitalypb.GitCommit{},
},
}
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
commits := []*gitalypb.GitCommit{}
rpcRequest := gitalypb.CommitsBetweenRequest{
Repository: testRepo, From: tc.from, To: tc.to,
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c, err := client.CommitsBetween(ctx, &rpcRequest)
if err != nil {
t.Fatal(err)
}
for {
resp, err := c.Recv()
if err == io.EOF {
break
} else if err != nil {
t.Fatal(err)
}
commits = append(commits, resp.GetCommits()...)
}
for i, commit := range commits {
require.Equal(t, expectedCommits[i], commit, "mismatched commits")
}
})
}
}
func TestFailedCommitsBetweenRequest(t *testing.T) {
server, serverSocketPath := startTestServices(t)
defer server.Stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
invalidRepo := &gitalypb.Repository{StorageName: "fake", RelativePath: "path"}
from := []byte("498214de67004b1da3d820901307bed2a68a8ef6")
to := []byte("e63f41fe459e62e1228fcef60d7189127aeba95a")
testCases := []struct {
description string
repository *gitalypb.Repository
from []byte
to []byte
code codes.Code
}{
{
description: "Invalid repository",
repository: invalidRepo,
from: from,
to: to,
code: codes.InvalidArgument,
},
{
description: "Repository is nil",
repository: nil,
from: from,
to: to,
code: codes.InvalidArgument,
},
{
description: "From is empty",
repository: testRepo,
from: nil,
to: to,
code: codes.InvalidArgument,
},
{
description: "To is empty",
repository: testRepo,
from: from,
to: nil,
code: codes.InvalidArgument,
},
{
description: "From begins with '-'",
from: append([]byte("-"), from...),
to: to,
code: codes.InvalidArgument,
},
{
description: "To begins with '-'",
from: from,
to: append([]byte("-"), to...),
code: codes.InvalidArgument,
},
}
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
rpcRequest := gitalypb.CommitsBetweenRequest{
Repository: tc.repository, From: tc.from, To: tc.to,
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c, err := client.CommitsBetween(ctx, &rpcRequest)
if err != nil {
t.Fatal(err)
}
err = drainCommitsBetweenResponse(c)
testhelper.RequireGrpcError(t, err, tc.code)
})
}
}
func drainCommitsBetweenResponse(c gitalypb.CommitService_CommitsBetweenClient) error {
var err error
for err == nil {
_, err = c.Recv()
}
return err
}
|