File: byte_buffer_pool_test.go

package info (click to toggle)
golang-github-viant-toolbox 0.33.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 1,280 kB
  • sloc: makefile: 16
file content (27 lines) | stat: -rw-r--r-- 541 bytes parent folder | download | duplicates (2)
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
package toolbox_test

import (
	"github.com/stretchr/testify/assert"
	"github.com/viant/toolbox"
	"testing"
)

func TestNewBytesBufferPool(t *testing.T) {
	pool := toolbox.NewBytesBufferPool(2, 1024)
	buf := pool.Get() //creates a new buffer pool is empty.
	assert.NotNil(t, buf)

	buf[1] = 0x2
	pool.Put(buf)
	pool.Put([]byte{0x1})
	pool.Put(buf) //get discarded
	{
		poolBuf := pool.Get()
		assert.Equal(t, uint8(0x2), poolBuf[1])
		assert.Equal(t, 1024, len(poolBuf))
	}
	{
		poolBuf := pool.Get()
		assert.Equal(t, 1, len(poolBuf))
	}
}