-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfiles_test.go
54 lines (49 loc) · 1.2 KB
/
files_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
package main
import (
"crypto/sha1"
"fmt"
"testing"
)
type testFile struct {
path string
fileLen int64
// SHA1 of fileLen bytes.
hash string
// SHA1 of the first 25 bytes only.
hashPieceA string
// SHA1 of bytes 25-49
hashPieceB string
}
var tests []testFile = []testFile{{
"testData/testFile",
8054,
// shasum testData/testFile | tr "[a-z]" "[A-Z]"
"BC6314A1D1D36EC6C0888AF9DBD3B5E826612ADA",
// dd if=testData/testFile bs=25 count=1 | shasum | tr "[a-z]" "[A-Z]"
"F072A5A05C7ED8EECFFB6524FBFA89CA725A66C3",
// dd if=testData/testFile bs=25 count=1 skip=1 | shasum | tr "[a-z]" "[A-Z]"
"859CF11E055E61296F42EEB5BB19E598626A5173",
}}
func mkFileStore(tf testFile) (fs *fileStore, err error) {
f := fileEntry{tf.fileLen, tf.path}
return &fileStore{[]int64{0}, []fileEntry{f}}, nil
}
func TestFileStoreRead(t *testing.T) {
for _, testFile := range tests {
fs, err := mkFileStore(testFile)
if err != nil {
t.Fatal(err)
}
ret := make([]byte, testFile.fileLen)
_, err = fs.ReadAt(ret, 0)
if err != nil {
t.Fatal(err)
}
h := sha1.New()
h.Write(ret)
sum := fmt.Sprintf("%X", h.Sum(nil))
if sum != testFile.hash {
t.Errorf("Wanted %v, got %v\n", testFile.hash, sum)
}
}
}