decode_stream_pool_test.go (1879B)
1 package gojay 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestDecodeStreamDecodePooledDecoderError(t *testing.T) { 10 // we override the pool chan 11 dec := Stream.NewDecoder(nil) 12 dec.Release() 13 defer func() { 14 err := recover() 15 assert.NotNil(t, err, "err shouldnt be nil") 16 assert.IsType(t, InvalidUsagePooledDecoderError(""), err, "err should be of type InvalidUsagePooledDecoderError") 17 }() 18 var v = 0 19 dec.Decode(&v) 20 // make sure it fails if this is called 21 assert.True(t, false, "should not be called as decoder should have panicked") 22 } 23 24 func TestDecodeStreamDecodePooledDecoderError1(t *testing.T) { 25 // we override the pool chan 26 dec := Stream.NewDecoder(nil) 27 dec.Release() 28 defer func() { 29 err := recover() 30 assert.NotNil(t, err, "err shouldnt be nil") 31 assert.IsType(t, InvalidUsagePooledDecoderError(""), err, "err should be of type InvalidUsagePooledDecoderError") 32 }() 33 var v = testSliceStrings{} 34 dec.DecodeArray(&v) 35 // make sure they are the same 36 assert.True(t, false, "should not be called as decoder should have panicked") 37 } 38 39 func TestDecodeStreamDecodePooledDecoderError2(t *testing.T) { 40 // we override the pool chan 41 dec := Stream.NewDecoder(nil) 42 dec.Release() 43 defer func() { 44 err := recover() 45 assert.NotNil(t, err, "err shouldnt be nil") 46 assert.IsType(t, InvalidUsagePooledDecoderError(""), err, "err should be of type InvalidUsagePooledDecoderError") 47 assert.Equal(t, "Invalid usage of pooled decoder", err.(InvalidUsagePooledDecoderError).Error(), "err should be of type InvalidUsagePooledDecoderError") 48 }() 49 var v = TestObj{} 50 dec.DecodeObject(&v) 51 // make sure they are the same 52 assert.True(t, false, "should not be called as decoder should have panicked") 53 } 54 55 func TestStreamDecoderNewPool(t *testing.T) { 56 dec := newStreamDecoderPool() 57 assert.IsType(t, &StreamDecoder{}, dec, "dec should be a *StreamDecoder") 58 }