forked from lightningnetwork/lnd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buffer_test.go
44 lines (39 loc) · 822 Bytes
/
buffer_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
package buffer_test
import (
"bytes"
"testing"
"github.com/lightningnetwork/lnd/buffer"
)
// TestRecycleSlice asserts that RecycleSlice always zeros a byte slice.
func TestRecycleSlice(t *testing.T) {
tests := []struct {
name string
slice []byte
}{
{
name: "length zero",
},
{
name: "length one",
slice: []byte("a"),
},
{
name: "length power of two length",
slice: bytes.Repeat([]byte("b"), 16),
},
{
name: "length non power of two",
slice: bytes.Repeat([]byte("c"), 27),
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
buffer.RecycleSlice(test.slice)
expSlice := make([]byte, len(test.slice))
if !bytes.Equal(expSlice, test.slice) {
t.Fatalf("slice not recycled, want: %v, got: %v",
expSlice, test.slice)
}
})
}
}