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
|
package commit
import (
"context"
"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"
"google.golang.org/grpc/codes"
)
func TestSuccessfulLastCommitForPathRequest(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()
commit := &gitalypb.GitCommit{
Id: "570e7b2abdd848b95f2f578043fc23bd6f6fd24d",
Subject: []byte("Change some files"),
Body: []byte("Change some files\n\nSigned-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>\n"),
Author: &gitalypb.CommitAuthor{
Name: []byte("Dmitriy Zaporozhets"),
Email: []byte("dmitriy.zaporozhets@gmail.com"),
Date: ×tamp.Timestamp{Seconds: 1393491451},
},
Committer: &gitalypb.CommitAuthor{
Name: []byte("Dmitriy Zaporozhets"),
Email: []byte("dmitriy.zaporozhets@gmail.com"),
Date: ×tamp.Timestamp{Seconds: 1393491451},
},
ParentIds: []string{"6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9"},
BodySize: 86,
}
testCases := []struct {
desc string
revision string
path []byte
commit *gitalypb.GitCommit
}{
{
desc: "path present",
revision: "e63f41fe459e62e1228fcef60d7189127aeba95a",
path: []byte("files/ruby/regex.rb"),
commit: commit,
},
{
desc: "path empty",
revision: "570e7b2abdd848b95f2f578043fc23bd6f6fd24d",
commit: commit,
},
{
desc: "path is '/'",
revision: "570e7b2abdd848b95f2f578043fc23bd6f6fd24d",
commit: commit,
path: []byte("/"),
},
{
desc: "file does not exist in this commit",
revision: "570e7b2abdd848b95f2f578043fc23bd6f6fd24d",
path: []byte("files/lfs/lfs_object.iso"),
},
}
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
request := &gitalypb.LastCommitForPathRequest{
Repository: testRepo,
Revision: []byte(testCase.revision),
Path: []byte(testCase.path),
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
response, err := client.LastCommitForPath(ctx, request)
if err != nil {
t.Fatal(err)
}
require.Equal(t, testCase.commit, response.GetCommit(), "mismatched commits")
})
}
}
func TestFailedLastCommitForPathRequest(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"}
testCases := []struct {
desc string
request *gitalypb.LastCommitForPathRequest
code codes.Code
}{
{
desc: "Invalid repository",
request: &gitalypb.LastCommitForPathRequest{Repository: invalidRepo},
code: codes.InvalidArgument,
},
{
desc: "Repository is nil",
request: &gitalypb.LastCommitForPathRequest{Revision: []byte("some-branch")},
code: codes.InvalidArgument,
},
{
desc: "Revision is missing",
request: &gitalypb.LastCommitForPathRequest{Repository: testRepo, Path: []byte("foo/bar")},
code: codes.InvalidArgument,
},
}
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
_, err := client.LastCommitForPath(ctx, testCase.request)
testhelper.RequireGrpcError(t, err, testCase.code)
})
}
}
|