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
|
package repository
import (
"context"
"path"
"path/filepath"
"testing"
"time"
"google.golang.org/grpc/codes"
"github.com/stretchr/testify/assert"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
pb "gitlab.com/gitlab-org/gitaly-proto/go"
)
func TestRepackIncrementalSuccess(t *testing.T) {
server := runRepoServer(t)
defer server.Stop()
client, conn := newRepositoryClient(t)
defer conn.Close()
packPath := path.Join(testhelper.GitlabTestStoragePath(), testRepo.GetRelativePath(), "objects", "pack")
// Reset mtime to a long while ago since some filesystems don't have sub-second
// precision on `mtime`.
// Stamp taken from https://golang.org/pkg/time/#pkg-constants
testhelper.MustRunCommand(t, nil, "touch", "-t", testTimeString, path.Join(packPath, "*"))
testTime := time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c, err := client.RepackIncremental(ctx, &pb.RepackIncrementalRequest{Repository: testRepo})
assert.NoError(t, err)
assert.NotNil(t, c)
// Entire `path`-folder gets updated so this is fine :D
assertModTimeAfter(t, testTime, packPath)
}
func TestRepackIncrementalFailure(t *testing.T) {
server := runRepoServer(t)
defer server.Stop()
client, conn := newRepositoryClient(t)
defer conn.Close()
tests := []struct {
repo *pb.Repository
code codes.Code
desc string
}{
{desc: "nil repo", repo: nil, code: codes.InvalidArgument},
{desc: "invalid storage name", repo: &pb.Repository{StorageName: "foo"}, code: codes.InvalidArgument},
{desc: "no storage name", repo: &pb.Repository{RelativePath: "bar"}, code: codes.InvalidArgument},
{desc: "non-existing repo", repo: &pb.Repository{StorageName: testRepo.GetStorageName(), RelativePath: "bar"}, code: codes.NotFound},
}
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
_, err := client.RepackIncremental(ctx, &pb.RepackIncrementalRequest{Repository: test.repo})
testhelper.AssertGrpcError(t, err, test.code, "")
})
}
}
func TestRepackFullSuccess(t *testing.T) {
server := runRepoServer(t)
defer server.Stop()
client, conn := newRepositoryClient(t)
defer conn.Close()
tests := []struct {
req *pb.RepackFullRequest
desc string
}{
{req: &pb.RepackFullRequest{Repository: testRepo, CreateBitmap: true}, desc: "with bitmap"},
{req: &pb.RepackFullRequest{Repository: testRepo, CreateBitmap: false}, desc: "without bitmap"},
}
packPath := path.Join(testhelper.GitlabTestStoragePath(), testRepo.GetRelativePath(), "objects", "pack")
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
// Reset mtime to a long while ago since some filesystems don't have sub-second
// precision on `mtime`.
testhelper.MustRunCommand(t, nil, "touch", "-t", testTimeString, packPath)
testTime := time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c, err := client.RepackFull(ctx, test.req)
assert.NoError(t, err)
assert.NotNil(t, c)
// Entire `path`-folder gets updated so this is fine :D
assertModTimeAfter(t, testTime, packPath)
bmPath, err := filepath.Glob(path.Join(packPath, "pack-*.bitmap"))
if err != nil {
t.Fatalf("Error globbing bitmaps: %v", err)
}
if test.req.GetCreateBitmap() {
if len(bmPath) == 0 {
t.Errorf("No bitmaps found")
}
} else {
if len(bmPath) != 0 {
t.Errorf("Bitmap found: %v", bmPath)
}
}
})
}
}
func TestRepackFullFailure(t *testing.T) {
server := runRepoServer(t)
defer server.Stop()
client, conn := newRepositoryClient(t)
defer conn.Close()
tests := []struct {
repo *pb.Repository
code codes.Code
desc string
}{
{desc: "nil repo", repo: nil, code: codes.InvalidArgument},
{desc: "invalid storage name", repo: &pb.Repository{StorageName: "foo"}, code: codes.InvalidArgument},
{desc: "no storage name", repo: &pb.Repository{RelativePath: "bar"}, code: codes.InvalidArgument},
{desc: "non-existing repo", repo: &pb.Repository{StorageName: testRepo.GetStorageName(), RelativePath: "bar"}, code: codes.NotFound},
}
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
_, err := client.RepackFull(ctx, &pb.RepackFullRequest{Repository: test.repo})
testhelper.AssertGrpcError(t, err, test.code, "")
})
}
}
|