chore: fix potential nil pointer errors (#3454)
This commit is contained in:
@@ -13,3 +13,26 @@ func TestBufferPool(t *testing.T) {
|
||||
pool.Put(bytes.NewBuffer(make([]byte, 0, 2*capacity)))
|
||||
assert.True(t, pool.Get().Cap() <= capacity)
|
||||
}
|
||||
|
||||
func TestBufferPool_Put(t *testing.T) {
|
||||
t.Run("with nil buf", func(t *testing.T) {
|
||||
pool := NewBufferPool(1024)
|
||||
pool.Put(nil)
|
||||
val := pool.Get()
|
||||
assert.IsType(t, new(bytes.Buffer), val)
|
||||
})
|
||||
|
||||
t.Run("with less-cap buf", func(t *testing.T) {
|
||||
pool := NewBufferPool(1024)
|
||||
pool.Put(bytes.NewBuffer(make([]byte, 0, 512)))
|
||||
val := pool.Get()
|
||||
assert.IsType(t, new(bytes.Buffer), val)
|
||||
})
|
||||
|
||||
t.Run("with more-cap buf", func(t *testing.T) {
|
||||
pool := NewBufferPool(1024)
|
||||
pool.Put(bytes.NewBuffer(make([]byte, 0, 1024<<1)))
|
||||
val := pool.Get()
|
||||
assert.IsType(t, new(bytes.Buffer), val)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user