-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbytePool_test.go
46 lines (38 loc) · 1016 Bytes
/
bytePool_test.go
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package pool
import (
// "fmt"
log "github.com/cihub/seelog"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestPool(t *testing.T) {
defer log.Flush()
Convey("use pool validate they aren't the same", t, func() {
pool := NewBytePool(5, 30)
bytes := pool.Get()
bytes2 := pool.Get()
So(bytes, ShouldNotEqual, bytes2)
})
Convey("modify pool, put back on and validate change is not visible with get", t, func() {
pool := NewBytePool(5, 30)
bytes := pool.Get()
bytes[0] = byte(1)
bytes[1] = byte(1)
pool.Put(bytes[:2])
bytes2 := pool.Get()
So(bytes2, ShouldResemble, make([]byte, 30))
})
Convey("exceed put buffer validate length", t, func() {
pool := NewBytePool(1, 30)
So(pool.Size(), ShouldEqual, 0)
bytes := pool.Get()
bytes2 := pool.Get()
pool.Put(bytes)
So(pool.Size(), ShouldEqual, 1)
pool.Put(bytes2)
So(pool.Size(), ShouldEqual, 1)
bytes3 := pool.Get()
So(bytes3, ShouldResemble, make([]byte, 30))
So(pool.Size(), ShouldEqual, 0)
})
}