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
|
package repository
import (
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"google.golang.org/grpc/codes"
)
// We assume that the combined size of the Git objects in the test
// repository, even in optimally packed state, is greater than this.
const testRepoMinSizeKB = 10000
func TestSuccessfulRepositorySizeRequest(t *testing.T) {
_, repo, _, client := setupRepositoryService(t)
request := &gitalypb.RepositorySizeRequest{Repository: repo}
ctx, cancel := testhelper.Context()
defer cancel()
response, err := client.RepositorySize(ctx, request)
require.NoError(t, err)
require.True(t,
response.Size > testRepoMinSizeKB,
"repository size %d should be at least %d", response.Size, testRepoMinSizeKB,
)
}
func TestFailedRepositorySizeRequest(t *testing.T) {
_, client := setupRepositoryServiceWithoutRepo(t)
testCases := []struct {
description string
repo *gitalypb.Repository
}{
{
description: "Invalid repo",
repo: &gitalypb.Repository{StorageName: "fake", RelativePath: "path"},
},
}
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
request := &gitalypb.RepositorySizeRequest{
Repository: testCase.repo,
}
ctx, cancel := testhelper.Context()
defer cancel()
_, err := client.RepositorySize(ctx, request)
testhelper.RequireGrpcError(t, err, codes.InvalidArgument)
})
}
}
func TestSuccessfulGetObjectDirectorySizeRequest(t *testing.T) {
_, repo, _, client := setupRepositoryService(t)
repo.GitObjectDirectory = "objects/"
ctx, cancel := testhelper.Context()
defer cancel()
request := &gitalypb.GetObjectDirectorySizeRequest{Repository: repo}
response, err := client.GetObjectDirectorySize(ctx, request)
require.NoError(t, err)
require.True(t,
response.Size > testRepoMinSizeKB,
"repository size %d should be at least %d", response.Size, testRepoMinSizeKB,
)
}
|