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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
|
package operations_test
//lint:file-ignore SA1019 due to planned removal in issue https://gitlab.com/gitlab-org/gitaly/issues/1628
import (
"errors"
"fmt"
"os"
"strings"
"testing"
"time"
"github.com/stretchr/testify/require"
gitlog "gitlab.com/gitlab-org/gitaly/internal/git/log"
"gitlab.com/gitlab-org/gitaly/internal/service/operations"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
)
var (
rebaseUser = &gitalypb.User{
Name: []byte("Ahmad Sherif"),
Email: []byte("ahmad@gitlab.com"),
GlId: "user-123",
}
branchName = "many_files"
)
func TestSuccessfulUserRebaseConfirmableRequest(t *testing.T) {
pushOptions := []string{"ci.skip", "test=value"}
ctxOuter, cancel := testhelper.Context()
defer cancel()
server, serverSocketPath := runFullServer(t)
defer server.Stop()
client, conn := operations.NewOperationClient(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
testRepoCopy, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
branchSha := getBranchSha(t, testRepoPath, branchName)
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
ctx := metadata.NewOutgoingContext(ctxOuter, md)
rebaseStream, err := client.UserRebaseConfirmable(ctx)
require.NoError(t, err)
preReceiveHookOutputPath := operations.WriteEnvToHook(t, testRepoPath, "pre-receive")
postReceiveHookOutputPath := operations.WriteEnvToHook(t, testRepoPath, "post-receive")
defer os.Remove(preReceiveHookOutputPath)
defer os.Remove(postReceiveHookOutputPath)
headerRequest := buildHeaderRequest(testRepo, rebaseUser, "1", branchName, branchSha, testRepoCopy, "master")
headerRequest.GetHeader().GitPushOptions = pushOptions
require.NoError(t, rebaseStream.Send(headerRequest), "send header")
firstResponse, err := rebaseStream.Recv()
require.NoError(t, err, "receive first response")
_, err = gitlog.GetCommit(ctx, testRepo, firstResponse.GetRebaseSha())
require.NoError(t, err, "look up git commit before rebase is applied")
applyRequest := buildApplyRequest(true)
require.NoError(t, rebaseStream.Send(applyRequest), "apply rebase")
secondResponse, err := rebaseStream.Recv()
require.NoError(t, err, "receive second response")
err = testhelper.ReceiveEOFWithTimeout(func() error {
_, err = rebaseStream.Recv()
return err
})
require.NoError(t, err, "consume EOF")
newBranchSha := getBranchSha(t, testRepoPath, branchName)
require.NotEqual(t, newBranchSha, branchSha)
require.Equal(t, newBranchSha, firstResponse.GetRebaseSha())
require.True(t, secondResponse.GetRebaseApplied(), "the second rebase is applied")
for _, outputPath := range []string{preReceiveHookOutputPath, postReceiveHookOutputPath} {
output := string(testhelper.MustReadFile(t, outputPath))
require.Contains(t, output, "GIT_PUSH_OPTION_COUNT=2")
require.Contains(t, output, "GIT_PUSH_OPTION_0=ci.skip")
require.Contains(t, output, "GIT_PUSH_OPTION_1=test=value")
}
}
func TestFailedRebaseUserRebaseConfirmableRequestDueToInvalidHeader(t *testing.T) {
ctxOuter, cancel := testhelper.Context()
defer cancel()
server, serverSocketPath := runFullServer(t)
defer server.Stop()
client, conn := operations.NewOperationClient(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
testRepoCopy, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
branchSha := getBranchSha(t, testRepoPath, branchName)
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
ctx := metadata.NewOutgoingContext(ctxOuter, md)
testCases := []struct {
desc string
req *gitalypb.UserRebaseConfirmableRequest
}{
{
desc: "empty Repository",
req: buildHeaderRequest(nil, rebaseUser, "1", branchName, branchSha, testRepoCopy, "master"),
},
{
desc: "empty User",
req: buildHeaderRequest(testRepo, nil, "1", branchName, branchSha, testRepoCopy, "master"),
},
{
desc: "empty Branch",
req: buildHeaderRequest(testRepo, rebaseUser, "1", "", branchSha, testRepoCopy, "master"),
},
{
desc: "empty BranchSha",
req: buildHeaderRequest(testRepo, rebaseUser, "1", branchName, "", testRepoCopy, "master"),
},
{
desc: "empty RemoteRepository",
req: buildHeaderRequest(testRepo, rebaseUser, "1", branchName, branchSha, nil, "master"),
},
{
desc: "empty RemoteBranch",
req: buildHeaderRequest(testRepo, rebaseUser, "1", branchName, branchSha, testRepoCopy, ""),
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
rebaseStream, err := client.UserRebaseConfirmable(ctx)
require.NoError(t, err)
require.NoError(t, rebaseStream.Send(tc.req), "send request header")
firstResponse, err := rebaseStream.Recv()
testhelper.RequireGrpcError(t, err, codes.InvalidArgument)
require.Contains(t, err.Error(), tc.desc)
require.Empty(t, firstResponse.GetRebaseSha(), "rebase sha on first response")
})
}
}
func TestAbortedUserRebaseConfirmable(t *testing.T) {
ctxOuter, cancel := testhelper.Context()
defer cancel()
server, serverSocketPath := runFullServer(t)
defer server.Stop()
client, conn := operations.NewOperationClient(t, serverSocketPath)
defer conn.Close()
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
ctx := metadata.NewOutgoingContext(ctxOuter, md)
testCases := []struct {
req *gitalypb.UserRebaseConfirmableRequest
closeSend bool
desc string
code codes.Code
}{
{req: &gitalypb.UserRebaseConfirmableRequest{}, desc: "empty request, don't close", code: codes.FailedPrecondition},
{req: &gitalypb.UserRebaseConfirmableRequest{}, closeSend: true, desc: "empty request and close", code: codes.FailedPrecondition},
{closeSend: true, desc: "no request just close", code: codes.Internal},
}
for i, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
testRepoCopy, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
branchSha := getBranchSha(t, testRepoPath, branchName)
headerRequest := buildHeaderRequest(testRepo, rebaseUser, fmt.Sprintf("%v", i), branchName, branchSha, testRepoCopy, "master")
rebaseStream, err := client.UserRebaseConfirmable(ctx)
require.NoError(t, err)
require.NoError(t, rebaseStream.Send(headerRequest), "send first request")
firstResponse, err := rebaseStream.Recv()
require.NoError(t, err, "receive first response")
require.NotEmpty(t, firstResponse.GetRebaseSha(), "rebase sha on first response")
if tc.req != nil {
require.NoError(t, rebaseStream.Send(tc.req), "send second request")
}
if tc.closeSend {
require.NoError(t, rebaseStream.CloseSend(), "close request stream from client")
}
secondResponse, err := recvTimeout(rebaseStream, 1*time.Second)
if err == errRecvTimeout {
t.Fatal(err)
}
require.False(t, secondResponse.GetRebaseApplied(), "rebase should not have been applied")
require.Error(t, err)
testhelper.RequireGrpcError(t, err, tc.code)
newBranchSha := getBranchSha(t, testRepoPath, branchName)
require.Equal(t, newBranchSha, branchSha, "branch should not change when the rebase is aborted")
})
}
}
func TestFailedUserRebaseConfirmableDueToApplyBeingFalse(t *testing.T) {
ctxOuter, cancel := testhelper.Context()
defer cancel()
server, serverSocketPath := runFullServer(t)
defer server.Stop()
client, conn := operations.NewOperationClient(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
testRepoCopy, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
branchSha := getBranchSha(t, testRepoPath, branchName)
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
ctx := metadata.NewOutgoingContext(ctxOuter, md)
rebaseStream, err := client.UserRebaseConfirmable(ctx)
require.NoError(t, err)
headerRequest := buildHeaderRequest(testRepo, rebaseUser, "1", branchName, branchSha, testRepoCopy, "master")
require.NoError(t, rebaseStream.Send(headerRequest), "send header")
firstResponse, err := rebaseStream.Recv()
require.NoError(t, err, "receive first response")
_, err = gitlog.GetCommit(ctx, testRepo, firstResponse.GetRebaseSha())
require.NoError(t, err, "look up git commit before rebase is applied")
applyRequest := buildApplyRequest(false)
require.NoError(t, rebaseStream.Send(applyRequest), "apply rebase")
secondResponse, err := rebaseStream.Recv()
require.Error(t, err, "second response should have error")
testhelper.RequireGrpcError(t, err, codes.FailedPrecondition)
require.False(t, secondResponse.GetRebaseApplied(), "the second rebase is not applied")
newBranchSha := getBranchSha(t, testRepoPath, branchName)
require.Equal(t, branchSha, newBranchSha, "branch should not change when the rebase is not applied")
require.NotEqual(t, newBranchSha, firstResponse.GetRebaseSha(), "branch should not be the sha returned when the rebase is not applied")
}
func TestFailedUserRebaseConfirmableRequestDueToPreReceiveError(t *testing.T) {
ctxOuter, cancel := testhelper.Context()
defer cancel()
server, serverSocketPath := runFullServer(t)
defer server.Stop()
client, conn := operations.NewOperationClient(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
testRepoCopy, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
branchSha := getBranchSha(t, testRepoPath, branchName)
hookContent := []byte("#!/bin/sh\necho 'failure'\nexit 1")
for i, hookName := range operations.GitlabPreHooks {
t.Run(hookName, func(t *testing.T) {
remove, err := operations.OverrideHooks(hookName, hookContent)
require.NoError(t, err, "set up hooks override")
defer remove()
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
ctx := metadata.NewOutgoingContext(ctxOuter, md)
rebaseStream, err := client.UserRebaseConfirmable(ctx)
require.NoError(t, err)
headerRequest := buildHeaderRequest(testRepo, rebaseUser, fmt.Sprintf("%v", i), branchName, branchSha, testRepoCopy, "master")
require.NoError(t, rebaseStream.Send(headerRequest), "send header")
firstResponse, err := rebaseStream.Recv()
require.NoError(t, err, "receive first response")
_, err = gitlog.GetCommit(ctx, testRepo, firstResponse.GetRebaseSha())
require.NoError(t, err, "look up git commit before rebase is applied")
applyRequest := buildApplyRequest(true)
require.NoError(t, rebaseStream.Send(applyRequest), "apply rebase")
secondResponse, err := rebaseStream.Recv()
require.NoError(t, err, "receive second response")
require.Contains(t, secondResponse.PreReceiveError, "failure")
err = testhelper.ReceiveEOFWithTimeout(func() error {
_, err = rebaseStream.Recv()
return err
})
require.NoError(t, err, "consume EOF")
newBranchSha := getBranchSha(t, testRepoPath, branchName)
require.Equal(t, branchSha, newBranchSha, "branch should not change when the rebase fails due to PreReceiveError")
require.NotEqual(t, newBranchSha, firstResponse.GetRebaseSha(), "branch should not be the sha returned when the rebase fails due to PreReceiveError")
})
}
}
func TestFailedUserRebaseConfirmableDueToGitError(t *testing.T) {
ctxOuter, cancel := testhelper.Context()
defer cancel()
server, serverSocketPath := runFullServer(t)
defer server.Stop()
client, conn := operations.NewOperationClient(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
testRepoCopy, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
failedBranchName := "rebase-encoding-failure-trigger"
branchSha := getBranchSha(t, testRepoPath, failedBranchName)
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
ctx := metadata.NewOutgoingContext(ctxOuter, md)
rebaseStream, err := client.UserRebaseConfirmable(ctx)
require.NoError(t, err)
headerRequest := buildHeaderRequest(testRepo, rebaseUser, "1", failedBranchName, branchSha, testRepoCopy, "master")
require.NoError(t, rebaseStream.Send(headerRequest), "send header")
firstResponse, err := rebaseStream.Recv()
require.NoError(t, err, "receive first response")
require.Contains(t, firstResponse.GitError, "error: Failed to merge in the changes.")
err = testhelper.ReceiveEOFWithTimeout(func() error {
_, err = rebaseStream.Recv()
return err
})
require.NoError(t, err, "consume EOF")
newBranchSha := getBranchSha(t, testRepoPath, failedBranchName)
require.Equal(t, branchSha, newBranchSha, "branch should not change when the rebase fails due to GitError")
}
// DEPRECATED: https://gitlab.com/gitlab-org/gitaly/issues/1628
func TestSuccessfulUserRebaseRequest(t *testing.T) {
ctxOuter, cancel := testhelper.Context()
defer cancel()
server, serverSocketPath := runFullServer(t)
defer server.Stop()
client, conn := operations.NewOperationClient(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
testRepoCopy, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
branchSha := getBranchSha(t, testRepoPath, branchName)
request := &gitalypb.UserRebaseRequest{
Repository: testRepo,
User: rebaseUser,
RebaseId: "1",
Branch: []byte(branchName),
BranchSha: branchSha,
RemoteRepository: testRepoCopy,
RemoteBranch: []byte("master"),
}
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
ctx := metadata.NewOutgoingContext(ctxOuter, md)
response, err := client.UserRebase(ctx, request)
require.NoError(t, err)
newBranchSha := getBranchSha(t, testRepoPath, branchName)
require.NotEqual(t, newBranchSha, branchSha)
require.Equal(t, newBranchSha, response.RebaseSha)
}
// DEPRECATED: https://gitlab.com/gitlab-org/gitaly/issues/1628
func TestFailedUserRebaseRequestDueToPreReceiveError(t *testing.T) {
ctxOuter, cancel := testhelper.Context()
defer cancel()
server, serverSocketPath := runFullServer(t)
defer server.Stop()
client, conn := operations.NewOperationClient(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
testRepoCopy, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
branchSha := getBranchSha(t, testRepoPath, branchName)
request := &gitalypb.UserRebaseRequest{
Repository: testRepo,
User: rebaseUser,
Branch: []byte(branchName),
BranchSha: branchSha,
RemoteRepository: testRepoCopy,
RemoteBranch: []byte("master"),
}
hookContent := []byte("#!/bin/sh\necho GL_ID=$GL_ID\nexit 1\n")
for i, hookName := range operations.GitlabPreHooks {
t.Run(hookName, func(t *testing.T) {
remove, err := operations.OverrideHooks(hookName, hookContent)
require.NoError(t, err, "set up hooks override")
defer remove()
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
ctx := metadata.NewOutgoingContext(ctxOuter, md)
request.RebaseId = fmt.Sprintf("%d", i+1)
response, err := client.UserRebase(ctx, request)
require.NoError(t, err)
require.Contains(t, response.PreReceiveError, "GL_ID="+rebaseUser.GlId)
})
}
}
// DEPRECATED: https://gitlab.com/gitlab-org/gitaly/issues/1628
func TestFailedUserRebaseRequestDueToGitError(t *testing.T) {
ctxOuter, cancel := testhelper.Context()
defer cancel()
server, serverSocketPath := runFullServer(t)
defer server.Stop()
client, conn := operations.NewOperationClient(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
testRepoCopy, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
failedBranchName := "rebase-encoding-failure-trigger"
branchSha := getBranchSha(t, testRepoPath, failedBranchName)
request := &gitalypb.UserRebaseRequest{
Repository: testRepo,
User: rebaseUser,
RebaseId: "1",
Branch: []byte(failedBranchName),
BranchSha: branchSha,
RemoteRepository: testRepoCopy,
RemoteBranch: []byte("master"),
}
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
ctx := metadata.NewOutgoingContext(ctxOuter, md)
response, err := client.UserRebase(ctx, request)
require.NoError(t, err)
require.Contains(t, response.GitError, "error: Failed to merge in the changes.")
}
// DEPRECATED: https://gitlab.com/gitlab-org/gitaly/issues/1628
func TestFailedUserRebaseRequestDueToValidations(t *testing.T) {
ctxOuter, cancel := testhelper.Context()
defer cancel()
server, serverSocketPath := runFullServer(t)
defer server.Stop()
client, conn := operations.NewOperationClient(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
testRepoCopy, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
testCases := []struct {
desc string
request *gitalypb.UserRebaseRequest
code codes.Code
}{
{
desc: "empty repository",
request: &gitalypb.UserRebaseRequest{
Repository: nil,
User: rebaseUser,
RebaseId: "1",
Branch: []byte("some-branch"),
BranchSha: "38008cb17ce1466d8fec2dfa6f6ab8dcfe5cf49e",
RemoteRepository: testRepoCopy,
RemoteBranch: []byte("master"),
},
code: codes.InvalidArgument,
},
{
desc: "empty user",
request: &gitalypb.UserRebaseRequest{
Repository: testRepo,
User: nil,
RebaseId: "1",
Branch: []byte("some-branch"),
BranchSha: "38008cb17ce1466d8fec2dfa6f6ab8dcfe5cf49e",
RemoteRepository: testRepoCopy,
RemoteBranch: []byte("master"),
},
code: codes.InvalidArgument,
},
{
desc: "empty rebase id",
request: &gitalypb.UserRebaseRequest{
Repository: testRepo,
User: rebaseUser,
RebaseId: "",
Branch: []byte("some-branch"),
BranchSha: "38008cb17ce1466d8fec2dfa6f6ab8dcfe5cf49e",
RemoteRepository: testRepoCopy,
RemoteBranch: []byte("master"),
},
code: codes.InvalidArgument,
},
{
desc: "empty branch",
request: &gitalypb.UserRebaseRequest{
Repository: testRepo,
User: rebaseUser,
RebaseId: "1",
Branch: nil,
BranchSha: "38008cb17ce1466d8fec2dfa6f6ab8dcfe5cf49e",
RemoteRepository: testRepoCopy,
RemoteBranch: []byte("master"),
},
code: codes.InvalidArgument,
},
{
desc: "empty branch sha",
request: &gitalypb.UserRebaseRequest{
Repository: testRepo,
User: rebaseUser,
RebaseId: "1",
Branch: []byte("some-branch"),
BranchSha: "",
RemoteRepository: testRepoCopy,
RemoteBranch: []byte("master"),
},
code: codes.InvalidArgument,
},
{
desc: "empty remote repository",
request: &gitalypb.UserRebaseRequest{
Repository: testRepo,
User: rebaseUser,
RebaseId: "1",
Branch: []byte("some-branch"),
BranchSha: "38008cb17ce1466d8fec2dfa6f6ab8dcfe5cf49e",
RemoteRepository: nil,
RemoteBranch: []byte("master"),
},
code: codes.InvalidArgument,
},
{
desc: "empty remote branch",
request: &gitalypb.UserRebaseRequest{
Repository: testRepo,
User: rebaseUser,
RebaseId: "1",
Branch: []byte("some-branch"),
BranchSha: "38008cb17ce1466d8fec2dfa6f6ab8dcfe5cf49e",
RemoteRepository: testRepoCopy,
RemoteBranch: nil,
},
code: codes.InvalidArgument,
},
}
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
ctx := metadata.NewOutgoingContext(ctxOuter, md)
_, err := client.UserRebase(ctx, testCase.request)
testhelper.RequireGrpcError(t, err, testCase.code)
})
}
}
func getBranchSha(t *testing.T, repoPath string, branchName string) string {
branchSha := string(testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "rev-parse", branchName))
return strings.TrimSpace(branchSha)
}
// This error is used as a sentinel value
var errRecvTimeout = errors.New("timeout waiting for response")
func recvTimeout(bidi gitalypb.OperationService_UserRebaseConfirmableClient, timeout time.Duration) (*gitalypb.UserRebaseConfirmableResponse, error) {
type responseError struct {
response *gitalypb.UserRebaseConfirmableResponse
err error
}
responseCh := make(chan responseError, 1)
go func() {
resp, err := bidi.Recv()
responseCh <- responseError{resp, err}
}()
select {
case respErr := <-responseCh:
return respErr.response, respErr.err
case <-time.After(timeout):
return nil, errRecvTimeout
}
}
func buildHeaderRequest(repo *gitalypb.Repository, user *gitalypb.User, rebaseId string, branchName string, branchSha string, remoteRepo *gitalypb.Repository, remoteBranch string) *gitalypb.UserRebaseConfirmableRequest {
return &gitalypb.UserRebaseConfirmableRequest{
UserRebaseConfirmableRequestPayload: &gitalypb.UserRebaseConfirmableRequest_Header_{
&gitalypb.UserRebaseConfirmableRequest_Header{
Repository: repo,
User: user,
RebaseId: rebaseId,
Branch: []byte(branchName),
BranchSha: branchSha,
RemoteRepository: remoteRepo,
RemoteBranch: []byte(remoteBranch),
},
},
}
}
func buildApplyRequest(apply bool) *gitalypb.UserRebaseConfirmableRequest {
return &gitalypb.UserRebaseConfirmableRequest{
UserRebaseConfirmableRequestPayload: &gitalypb.UserRebaseConfirmableRequest_Apply{
Apply: apply,
},
}
}
|