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
|
package commit
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"gitlab.com/gitlab-org/gitaly-proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"google.golang.org/grpc/codes"
)
func TestCommitStatsSuccess(t *testing.T) {
server, serverSocketPath := startTestServices(t)
defer server.Stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
tests := []struct {
revision []byte
oid string
additions, deletions int32
}{
{
revision: []byte("test-do-not-touch"),
oid: "899d3d27b04690ac1cd9ef4d8a74fde0667c57f1",
additions: 27,
deletions: 59,
},
{
revision: []byte("899d3d27b04690ac1cd9ef4d8a74fde0667c57f1"),
oid: "899d3d27b04690ac1cd9ef4d8a74fde0667c57f1",
additions: 27,
deletions: 59,
},
}
for _, tc := range tests {
resp, err := client.CommitStats(ctx, &gitalypb.CommitStatsRequest{Repository: testRepo, Revision: tc.revision})
assert.NoError(t, err)
assert.Equal(t, tc.oid, resp.GetOid())
assert.Equal(t, tc.additions, resp.GetAdditions())
assert.Equal(t, tc.deletions, resp.GetDeletions())
}
}
func TestCommitStatsFailure(t *testing.T) {
server, serverSocketPath := startTestServices(t)
defer server.Stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
tests := []struct {
desc string
repo *gitalypb.Repository
revision []byte
err codes.Code
}{
{
desc: "repo not found",
repo: &gitalypb.Repository{StorageName: testRepo.GetStorageName(), RelativePath: "bar.git"},
revision: []byte("test-do-not-touch"),
err: codes.NotFound,
},
{
desc: "storage not found",
repo: &gitalypb.Repository{StorageName: "foo", RelativePath: "bar.git"},
revision: []byte("test-do-not-touch"),
err: codes.InvalidArgument,
},
{
desc: "ref not found",
repo: testRepo,
revision: []byte("non/existing"),
err: codes.Internal,
},
}
for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
_, err := client.CommitStats(ctx, &gitalypb.CommitStatsRequest{Repository: tc.repo, Revision: tc.revision})
testhelper.RequireGrpcError(t, err, tc.err)
})
}
}
|