-
Notifications
You must be signed in to change notification settings - Fork 35
/
writer_test.go
99 lines (81 loc) · 1.91 KB
/
writer_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package keyctl
import (
"testing"
)
func TestStreamWriter(t *testing.T) {
blk1 := helperRandBlock(1544)
ring, err := SessionKeyring()
if err != nil {
t.Fatal(err)
}
w, err := CreateWriter("test1544bytestream", ring)
if err != nil {
t.Fatal(err)
}
i, err := w.Write(blk1)
if err != nil {
t.Fatal(err)
}
if err = w.Close(); err != nil {
t.Fatal(err)
}
if i != len(blk1) {
t.Fatalf("write mismatch (%d!=%d)", len(blk1), i)
}
helperCompareBlock(t, "test1544bytestream", blk1, ring)
t.Logf("compared %d random block key in common session ring: %v", len(blk1), blk1[:200])
}
func TestStreamWriterUpdate(t *testing.T) {
blk1 := helperRandBlock(218)
ring, err := SessionKeyring()
if err != nil {
t.Fatal(err)
}
ring, err = CreateKeyring(ring, "test")
var key *Key
for key == nil {
key, err = ring.Search("test218bytestream")
if err != nil {
key, err = ring.Add("test218bytestream", []byte{0})
if err != nil {
t.Fatal(err)
}
}
}
w := NewWriter(key)
i, err := w.Write(blk1)
if err != nil {
t.Fatal(err)
}
if err = w.(Flusher).Flush(); err != nil {
t.Fatal(err)
}
if i != len(blk1) {
t.Fatalf("write mismatch (%d!=%d)", len(blk1), i)
}
helperCompareBlock(t, "test218bytestream", blk1, ring)
t.Logf("[flushed] compared %d random block key in %q ring: %v", len(blk1), ring.(NamedKeyring).Name(), blk1)
}
func TestStreamWriterFlush(t *testing.T) {
blk1 := helperRandBlock(218)
ring, err := SessionKeyring()
if err != nil {
t.Fatal(err)
}
w, err := CreateWriter("test218bytestream", ring)
if err != nil {
t.Fatal(err)
}
i, err := w.Write(blk1)
if err != nil {
t.Fatal(err)
}
if err = w.(Flusher).Flush(); err != nil {
t.Fatal(err)
}
if i != len(blk1) {
t.Fatalf("write mismatch (%d!=%d)", len(blk1), i)
}
helperCompareBlock(t, "test218bytestream", blk1, ring)
t.Logf("[flushed] compared %d random block key in common session ring: %v", len(blk1), blk1)
}