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
|
package ref
import (
"context"
"testing"
"gitlab.com/gitlab-org/gitaly-proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"google.golang.org/grpc/codes"
)
func TestFindRefNameSuccess(t *testing.T) {
server, serverSocketPath := runRefServiceServer(t)
defer server.Stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
rpcRequest := &gitalypb.FindRefNameRequest{
Repository: testRepo,
CommitId: "0b4bc9a49b562e85de7cc9e834518ea6828729b9",
Prefix: []byte(`refs/heads/`),
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c, err := client.FindRefName(ctx, rpcRequest)
if err != nil {
t.Fatal(err)
}
response := string(c.GetName())
if response != `refs/heads/expand-collapse-diffs` {
t.Errorf("Expected FindRefName to return `refs/heads/expand-collapse-diffs`, got `%#v`", response)
}
}
func TestFindRefNameEmptyCommit(t *testing.T) {
server, serverSocketPath := runRefServiceServer(t)
defer server.Stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
rpcRequest := &gitalypb.FindRefNameRequest{
Repository: testRepo,
CommitId: "",
Prefix: []byte(`refs/heads/`),
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c, err := client.FindRefName(ctx, rpcRequest)
if err == nil {
t.Fatalf("Expected FindRefName to throw an error")
}
if helper.GrpcCode(err) != codes.InvalidArgument {
t.Errorf("Expected FindRefName to throw InvalidArgument, got %v", err)
}
response := string(c.GetName())
if response != `` {
t.Errorf("Expected FindRefName to return empty-string, got %q", response)
}
}
func TestFindRefNameInvalidRepo(t *testing.T) {
server, serverSocketPath := runRefServiceServer(t)
defer server.Stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
repo := &gitalypb.Repository{StorageName: "fake", RelativePath: "path"}
rpcRequest := &gitalypb.FindRefNameRequest{
Repository: repo,
CommitId: "0b4bc9a49b562e85de7cc9e834518ea6828729b9",
Prefix: []byte(`refs/heads/`),
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c, err := client.FindRefName(ctx, rpcRequest)
if err == nil {
t.Fatalf("Expected FindRefName to throw an error")
}
if helper.GrpcCode(err) != codes.InvalidArgument {
t.Errorf("Expected FindRefName to throw InvalidArgument, got %v", err)
}
response := string(c.GetName())
if response != `` {
t.Errorf("Expected FindRefName to return empty-string, got %q", response)
}
}
func TestFindRefNameInvalidPrefix(t *testing.T) {
server, serverSocketPath := runRefServiceServer(t)
defer server.Stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
rpcRequest := &gitalypb.FindRefNameRequest{
Repository: testRepo,
CommitId: "0b4bc9a49b562e85de7cc9e834518ea6828729b9",
Prefix: []byte(`refs/nonexistant/`),
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c, err := client.FindRefName(ctx, rpcRequest)
if err != nil {
t.Fatalf("Expected FindRefName to not throw an error: %v", err)
}
if len(c.Name) > 0 {
t.Errorf("Expected empty name, got %q instead", c.Name)
}
}
func TestFindRefNameInvalidObject(t *testing.T) {
server, serverSocketPath := runRefServiceServer(t)
defer server.Stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
rpcRequest := &gitalypb.FindRefNameRequest{
Repository: testRepo,
CommitId: "dead1234dead1234dead1234dead1234dead1234",
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c, err := client.FindRefName(ctx, rpcRequest)
if err != nil {
t.Fatalf("Expected FindRefName to not throw an error")
}
if len(c.GetName()) > 0 {
t.Errorf("Expected FindRefName to return empty-string, got %q", string(c.GetName()))
}
}
|