-
Notifications
You must be signed in to change notification settings - Fork 2
/
encode_decode_test.go
80 lines (62 loc) · 1.43 KB
/
encode_decode_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
package compress
import (
"bytes"
"io"
"testing"
)
type encoder struct {
writer io.Writer
}
func (a *algorithm) NewEncoder(w io.Writer, opts ...EncoderOption) (Encoder, error) {
return &encoder{writer: w}, nil
}
func (e *encoder) SetEndian(endian Endian) error {
return nil
}
func (e *encoder) SetLitWidth(width int) error {
return nil
}
func (e *encoder) SetLevel(level Level) error {
return nil
}
func (e *encoder) Write(v []byte) (int, error) {
return e.writer.Write(v)
}
func (e *encoder) Close() error {
return nil
}
type decoder struct {
reader io.Reader
}
func (a *algorithm) NewDecoder(r io.Reader, opts ...DecoderOption) (Decoder, error) {
return &decoder{reader: r}, nil
}
func (d *decoder) SetOrder(o int) error {
return nil
}
func (d *decoder) SetLitWidth(w int) error {
return nil
}
func (d *decoder) Read(v []byte) (int, error) {
return d.reader.Read(v)
}
func (d *decoder) Close() error {
return nil
}
func TestEncodeDecode(t *testing.T) {
exp := []byte("abc123\ndef456\nabc123\ndef456\nabc123\ndef456\n")
encoded, err := Encode("mock", exp)
if err != nil {
t.Error(err)
}
if got, err := Decode("mock", encoded); err != nil {
t.Error(err)
} else if !bytes.Equal(exp, got) {
t.Error("decode response doesn't match what was encoded")
}
}
func TestNewEncoder(t *testing.T) {
if _, err := NewDecoder("foo", bytes.NewBuffer([]byte(""))); err == nil {
t.Error("foo should not be a registered algorithm")
}
}