-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathpackfiles_test.go
60 lines (50 loc) · 1.44 KB
/
packfiles_test.go
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
package gitbase
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
)
var testSivaFilePath = filepath.Join("_testdata", "fff7062de8474d10a67d417ccea87ba6f58ca81d.siva")
func TestRepositoryPackfiles(t *testing.T) {
require := require.New(t)
repo := sivaRepo("siva", testSivaFilePath, cache.NewObjectLRUDefault())
f, err := repo.FS()
require.NoError(err)
fs, packfiles, err := repositoryPackfiles(f)
require.NoError(err)
require.Equal([]plumbing.Hash{
plumbing.NewHash("5d2ce6a45cb07803f9b0c8040e730f5715fc7144"),
plumbing.NewHash("433e5205f6e26099e7d34ba5e5306f69e4cef12b"),
}, packfiles)
require.NotNil(fs)
}
func TestRepositoryIndex(t *testing.T) {
idx, err := newRepositoryIndex(sivaRepo("siva", testSivaFilePath, cache.NewObjectLRUDefault()))
require.NoError(t, err)
testCases := []struct {
hash string
offset int64
packfile string
}{
{
"52c853392c25d3a670446641f4b44b22770b3bbe",
3046713,
"5d2ce6a45cb07803f9b0c8040e730f5715fc7144",
},
{
"aa7ef7dafd292737ed493b7d74c0abfa761344f4",
3046902,
"5d2ce6a45cb07803f9b0c8040e730f5715fc7144",
},
}
for _, tt := range testCases {
t.Run(tt.hash, func(t *testing.T) {
offset, packfile, err := idx.find(plumbing.NewHash(tt.hash))
require.NoError(t, err)
require.Equal(t, tt.offset, offset)
require.Equal(t, tt.packfile, packfile.String())
})
}
}