From 1a7a42a7e437933e405804029813ba913f42cef9 Mon Sep 17 00:00:00 2001 From: Wessie Date: Wed, 21 Feb 2024 02:03:58 +0000 Subject: [PATCH] util/pool: add test --- util/pool/pool.go | 2 +- util/pool/pool_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 util/pool/pool_test.go diff --git a/util/pool/pool.go b/util/pool/pool.go index fe2de021..50356eb2 100644 --- a/util/pool/pool.go +++ b/util/pool/pool.go @@ -39,5 +39,5 @@ func NewResetPool[T Resetable](newFn func() T) *ResetPool[T] { func (p *ResetPool[T]) Put(v T) { v.Reset() - p.p.Put(v) + p.Pool.Put(v) } diff --git a/util/pool/pool_test.go b/util/pool/pool_test.go new file mode 100644 index 00000000..f920b72c --- /dev/null +++ b/util/pool/pool_test.go @@ -0,0 +1,30 @@ +package pool_test + +import ( + "testing" + + "github.com/R-a-dio/valkyrie/util/pool" + "github.com/stretchr/testify/assert" +) + +type testResetable struct { + called bool +} + +func (tr *testResetable) Reset() { + tr.called = true +} + +func TestResetPool(t *testing.T) { + var called bool + p := pool.NewResetPool(func() *testResetable { + called = true + return &testResetable{} + }) + + x := p.Get() + assert.True(t, called) + + p.Put(x) + assert.True(t, x.called) +}