fix: fix pool unit test

This commit is contained in:
supermario1990
2022-12-03 22:27:20 +08:00
parent a6502f1543
commit 3e1f901e42

View File

@@ -7,15 +7,21 @@ import (
"github.com/stretchr/testify/assert"
)
func TestPool(t *testing.T) {
// THE Magic Number
magicNumber := 42
intType := reflect.TypeOf(magicNumber)
// init int pool
reflectTypePools.Init(intType)
reflectTypePools.Put(intType, magicNumber)
// Get() will remove element from pool
assert.Equal(t, magicNumber, reflectTypePools.Get(intType).(int))
type Elem struct {
// magicNumber the Magic Number
magicNumber int
}
func (e Elem) Reset() {
}
func TestPool(t *testing.T) {
elem := Elem{42}
elemType := reflect.TypeOf(elem)
// init Elem pool
reflectTypePools.Init(elemType)
reflectTypePools.Put(elemType, elem)
// Get() will remove element from pool
assert.Equal(t, elem.magicNumber, reflectTypePools.Get(elemType).(Elem).magicNumber)
}