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
|
package repository
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
)
func TestFsckSuccess(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
_, repo, _, client := setupRepositoryService(t)
c, err := client.Fsck(ctx, &gitalypb.FsckRequest{Repository: repo})
assert.NoError(t, err)
assert.NotNil(t, c)
assert.Empty(t, c.GetError())
}
func TestFsckFailureSeverelyBrokenRepo(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
_, repo, repoPath, client := setupRepositoryService(t)
// This makes the repo severely broken so that `git` does not identify it as a
// proper repo.
require.NoError(t, os.RemoveAll(filepath.Join(repoPath, "objects")))
fd, err := os.Create(filepath.Join(repoPath, "objects"))
require.NoError(t, err)
require.NoError(t, fd.Close())
c, err := client.Fsck(ctx, &gitalypb.FsckRequest{Repository: repo})
assert.NoError(t, err)
assert.NotNil(t, c)
assert.Contains(t, strings.ToLower(string(c.GetError())), "not a git repository")
}
func TestFsckFailureSlightlyBrokenRepo(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
_, repo, repoPath, client := setupRepositoryService(t)
// This makes the repo slightly broken so that `git` still identify it as a
// proper repo, but `fsck` complains about broken refs...
require.NoError(t, os.RemoveAll(filepath.Join(repoPath, "objects", "pack")))
c, err := client.Fsck(ctx, &gitalypb.FsckRequest{Repository: repo})
assert.NoError(t, err)
assert.NotNil(t, c)
assert.NotEmpty(t, string(c.GetError()))
assert.Contains(t, string(c.GetError()), "error: HEAD: invalid sha1 pointer")
}
|