-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinode_reader_test.go
62 lines (43 loc) · 1.11 KB
/
inode_reader_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
package ext4
import (
"bytes"
"io"
"testing"
"io/ioutil"
"github.com/dsoprea/go-logging"
)
func TestInodeReader_Read(t *testing.T) {
f, inode, err := GetTestInode(TestFileInodeNumber)
log.PanicIf(err)
defer f.Close()
en := NewExtentNavigatorWithReadSeeker(f, inode)
var r io.Reader
r = NewInodeReader(en)
actualBytes, err := ioutil.ReadAll(r)
log.PanicIf(err)
expectedBytes, err := ioutil.ReadFile("assets/thejungle.txt")
log.PanicIf(err)
if bytes.Compare(actualBytes, expectedBytes) != 0 {
t.Fatalf("Bytes not read correctly.")
}
}
func TestInodeReader_Skip(t *testing.T) {
f, inode, err := GetTestInode(TestFileInodeNumber)
log.PanicIf(err)
defer f.Close()
en := NewExtentNavigatorWithReadSeeker(f, inode)
ir := NewInodeReader(en)
skipCount := uint64(1000)
for skipCount > 0 {
n, err := ir.Skip(skipCount)
log.PanicIf(err)
skipCount -= n
}
actualBytes, err := ioutil.ReadAll(ir)
log.PanicIf(err)
expectedBytes, err := ioutil.ReadFile("assets/thejungle.txt")
log.PanicIf(err)
if bytes.Compare(actualBytes, expectedBytes[1000:]) != 0 {
t.Fatalf("Bytes not read correctly.")
}
}