-
Notifications
You must be signed in to change notification settings - Fork 35
/
reader_test.go
50 lines (40 loc) · 927 Bytes
/
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
package keyctl
import (
"io"
"testing"
)
func helperSetRandBlock(name string, sz int) (key Id, ring Keyring, blk []byte, err error) {
if ring, err = SessionKeyring(); err != nil {
return
}
blk = helperRandBlock(sz)
if key, err = ring.Search(name); err != nil {
key, err = ring.Add(name, blk)
return
}
err = key.(*Key).Set(blk)
return
}
func TestStreamReader(t *testing.T) {
key, ring, blk, err := helperSetRandBlock("test1544bytestream", 719)
if err != nil {
t.Fatal(err)
}
r, err := OpenReader("test1544bytestream", ring)
if err != nil {
t.Fatal(err)
}
var i int
buf := make([]byte, 128)
for i, err = r.Read(buf); err == nil; i, err = r.Read(buf) {
helperCmp(t, blk[:i], buf[:i])
t.Logf("compared key %v %d bytes: %v", key.Id(), i, blk[:i])
blk = blk[i:]
}
if err != io.EOF {
t.Fatal(err)
}
if len(blk) != 0 {
t.Fatalf("Read on key returned excess %d bytes", len(blk))
}
}