forked from peterbourgon/diskv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream_test.go
More file actions
44 lines (36 loc) · 806 Bytes
/
stream_test.go
File metadata and controls
44 lines (36 loc) · 806 Bytes
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
package diskv
import (
"bytes"
"io/ioutil"
"testing"
)
func TestBasicStreamCaching(t *testing.T) {
d := New(Options{
BasePath: "test-data",
Transform: func(string) []string { return []string{} },
CacheSizeMax: 1024,
})
defer d.EraseAll()
input := "a1b2c3"
key, writeBuf, sync := "a", bytes.NewBufferString(input), true
if err := d.WriteStream(key, writeBuf, sync); err != nil {
t.Fatal(err)
}
if d.isCached(key) {
t.Fatalf("'%s' cached, but shouldn't be (yet)")
}
rc, err := d.ReadStream(key)
if err != nil {
t.Fatal(err)
}
readBuf, err := ioutil.ReadAll(rc)
if err != nil {
t.Fatal(err)
}
if !cmpBytes(readBuf, []byte(input)) {
t.Fatalf("'%s' != '%s'", string(readBuf), input)
}
if !d.isCached(key) {
t.Fatalf("'%s' isn't cached, but should be")
}
}