-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader_test.go
53 lines (51 loc) · 1.04 KB
/
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
package bitcask
import (
"bytes"
"io/ioutil"
"os"
"testing"
)
func TestReader(t *testing.T) {
path, err := ioutil.TempDir(".", "tmp")
if err != nil {
t.Fatal()
}
defer func() {
err := os.RemoveAll(path)
if err != nil {
t.Fail()
}
}()
loc := &location{
fileno: 101,
offset: 0,
length: 10,
}
cxt := &context{path: path,
limitOpt: LimitOption{
MaxFileSize: 100,
}}
bs := []byte("abcdefghijklmnopqrstuvwxyz0123456789")
if f, err := uOpenAppend(FT_Data, loc.fileno, cxt); err != nil {
t.Fatal()
} else {
f.Write(bs)
f.Close()
}
r := *newReader(cxt)
if q, _ := r.read(loc); len(q) != loc.length || !bytes.Equal(q, bs[loc.offset:loc.offset+loc.length]) {
t.Error(q)
}
loc.offset = 4
if q, _ := r.read(loc); len(q) != loc.length || !bytes.Equal(q, bs[loc.offset:loc.offset+loc.length]) {
t.Error(q)
}
loc.length = 12
if q, _ := r.read(loc); len(q) != loc.length || !bytes.Equal(q, bs[loc.offset:loc.offset+loc.length]) {
t.Error(q)
}
loc.fileno = 1
if q, _ := r.read(loc); len(q) != 0 {
t.Error()
}
}