Fixed flakty pool test.

Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
pull/7158/head
Bartlomiej Plotka 5 years ago
parent 86ff4a1717
commit 1bd55973c3

@ -20,59 +20,31 @@ import (
) )
func makeFunc(size int) interface{} { func makeFunc(size int) interface{} {
return size return make([]int, 0, size)
} }
func TestGet(t *testing.T) { func TestPool(t *testing.T) {
testPool := New(1, 8, 2, makeFunc) testPool := New(1, 8, 2, makeFunc)
cases := []struct { cases := []struct {
size int size int
expected int expectedCap int
}{ }{
{ {
size: -1, size: -1,
expected: 1, expectedCap: 1,
}, },
{ {
size: 3, size: 3,
expected: 4, expectedCap: 4,
}, },
{ {
size: 10, size: 10,
expected: 10, expectedCap: 10,
}, },
} }
for _, c := range cases { for _, c := range cases {
ret := testPool.Get(c.size) ret := testPool.Get(c.size)
testutil.Equals(t, c.expected, ret) testutil.Equals(t, c.expectedCap, cap(ret.([]int)))
} testPool.Put(ret)
}
func TestPut(t *testing.T) {
testPool := New(1, 8, 2, makeFunc)
cases := []struct {
slice []int
size int
expected interface{}
}{
{
slice: make([]int, 1),
size: 1,
expected: []int{},
},
{
slice: make([]int, 8),
size: 8,
expected: []int{},
},
{
slice: nil,
size: 2,
expected: 2,
},
}
for _, c := range cases {
testPool.Put(c.slice)
testutil.Equals(t, c.expected, testPool.Get(c.size))
} }
} }

Loading…
Cancel
Save