-
Notifications
You must be signed in to change notification settings - Fork 123
/
checksum_test.go
103 lines (80 loc) · 2.09 KB
/
checksum_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
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
package gitbase
import (
"fmt"
"os"
"path/filepath"
"testing"
fixtures "github.com/src-d/go-git-fixtures"
"github.com/stretchr/testify/require"
"gopkg.in/src-d/go-billy.v4/osfs"
)
const (
checksumMulti = "W/lxpR0jZ6O6BqVANTYTDMlAS/4="
checksumSingle = "zqLF31JlrtJ57XNC+cQ+2hSkBkw="
checksumSiva = "X27U+Lww5UOk1+/21bVFgI4uJyM="
)
func TestChecksum(t *testing.T) {
require := require.New(t)
defer func() {
require.NoError(fixtures.Clean())
}()
lib, pool, err := newMultiPool()
require.NoError(err)
for i, f := range fixtures.ByTag("worktree") {
path := f.Worktree().Root()
require.NoError(lib.AddPlain(fmt.Sprintf("repo_%d", i), path, nil))
}
c := &checksumable{pool}
checksum, err := c.Checksum()
require.NoError(err)
require.Equal(checksumMulti, checksum)
lib, pool, err = newMultiPool()
require.NoError(err)
path := fixtures.ByTag("worktree").One().Worktree().Root()
require.NoError(lib.AddPlain("worktree", path, nil))
c = &checksumable{pool}
checksum, err = c.Checksum()
require.NoError(err)
require.Equal(checksumSingle, checksum)
}
func TestChecksumSiva(t *testing.T) {
require := require.New(t)
lib, pool, err := newMultiPool()
require.NoError(err)
cwd, err := os.Getwd()
require.NoError(err)
cwdFS := osfs.New(cwd)
require.NoError(
filepath.Walk("_testdata", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if IsSivaFile(path) {
require.NoError(lib.AddSiva(path, cwdFS))
}
return nil
}),
)
c := &checksumable{pool}
checksum, err := c.Checksum()
require.NoError(err)
require.Equal(checksumSiva, checksum)
}
func TestChecksumStable(t *testing.T) {
require := require.New(t)
defer func() {
require.NoError(fixtures.Clean())
}()
lib, pool, err := newMultiPool()
require.NoError(err)
for i, f := range fixtures.ByTag("worktree") {
path := f.Worktree().Root()
require.NoError(lib.AddPlain(fmt.Sprintf("repo_%d", i), path, nil))
}
c := &checksumable{pool}
for i := 0; i < 100; i++ {
checksum, err := c.Checksum()
require.NoError(err)
require.Equal(checksumMulti, checksum)
}
}