blob: b736fb22197973a339e718df505401040cef1b6e (
plain) (
blame)
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
|
package sync
import (
"bytes"
"compress/zlib"
"io"
"testing"
)
func TestGetAndPutZlibReader(t *testing.T) {
_, err := GetZlibReader(bytes.NewReader(zlibInitBytes))
if err != nil {
t.Errorf("unexpected error: %v", err)
}
dict := &[]byte{}
reader := FakeZLibReader{}
PutZlibReader(ZLibReader{dict: dict, Reader: &reader})
if !reader.wasClosed {
t.Errorf("reader was not closed")
}
z2, err := GetZlibReader(bytes.NewReader(zlibInitBytes))
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if dict != z2.dict {
t.Errorf("zlib dictionary was not reused")
}
if &reader != z2.Reader {
t.Errorf("zlib reader was not reused")
}
if !reader.wasReset {
t.Errorf("reader was not reset")
}
}
func TestGetAndPutZlibWriter(t *testing.T) {
w := GetZlibWriter(nil)
if w == nil {
t.Errorf("nil was not expected")
}
newW := zlib.NewWriter(nil)
PutZlibWriter(newW)
w2 := GetZlibWriter(nil)
if w2 != newW {
t.Errorf("zlib writer was not reused")
}
}
type FakeZLibReader struct {
wasClosed bool
wasReset bool
}
func (f *FakeZLibReader) Reset(r io.Reader, dict []byte) error {
f.wasReset = true
return nil
}
func (f *FakeZLibReader) Read(p []byte) (n int, err error) {
return 0, nil
}
func (f *FakeZLibReader) Close() error {
f.wasClosed = true
return nil
}
|