-
Notifications
You must be signed in to change notification settings - Fork 114
/
decode_stream_pool_test.go
58 lines (52 loc) · 1.83 KB
/
decode_stream_pool_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
package gojay
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestDecodeStreamDecodePooledDecoderError(t *testing.T) {
// we override the pool chan
dec := Stream.NewDecoder(nil)
dec.Release()
defer func() {
err := recover()
assert.NotNil(t, err, "err shouldnt be nil")
assert.IsType(t, InvalidUsagePooledDecoderError(""), err, "err should be of type InvalidUsagePooledDecoderError")
}()
var v = 0
dec.Decode(&v)
// make sure it fails if this is called
assert.True(t, false, "should not be called as decoder should have panicked")
}
func TestDecodeStreamDecodePooledDecoderError1(t *testing.T) {
// we override the pool chan
dec := Stream.NewDecoder(nil)
dec.Release()
defer func() {
err := recover()
assert.NotNil(t, err, "err shouldnt be nil")
assert.IsType(t, InvalidUsagePooledDecoderError(""), err, "err should be of type InvalidUsagePooledDecoderError")
}()
var v = testSliceStrings{}
dec.DecodeArray(&v)
// make sure they are the same
assert.True(t, false, "should not be called as decoder should have panicked")
}
func TestDecodeStreamDecodePooledDecoderError2(t *testing.T) {
// we override the pool chan
dec := Stream.NewDecoder(nil)
dec.Release()
defer func() {
err := recover()
assert.NotNil(t, err, "err shouldnt be nil")
assert.IsType(t, InvalidUsagePooledDecoderError(""), err, "err should be of type InvalidUsagePooledDecoderError")
assert.Equal(t, "Invalid usage of pooled decoder", err.(InvalidUsagePooledDecoderError).Error(), "err should be of type InvalidUsagePooledDecoderError")
}()
var v = TestObj{}
dec.DecodeObject(&v)
// make sure they are the same
assert.True(t, false, "should not be called as decoder should have panicked")
}
func TestStreamDecoderNewPool(t *testing.T) {
dec := newStreamDecoderPool()
assert.IsType(t, &StreamDecoder{}, dec, "dec should be a *StreamDecoder")
}