-
Notifications
You must be signed in to change notification settings - Fork 1
/
item_buffer_test.go
73 lines (66 loc) · 1.52 KB
/
item_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package dynamoql_test
import (
"testing"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
"github.com/maestre3d/dynamoql-go"
"github.com/stretchr/testify/assert"
)
func TestNewItemBuffer(t *testing.T) {
tests := []struct {
name string
size int
grow int
}{
{
name: "empty",
size: 0,
grow: 0,
},
{
name: "copy grow",
size: 10,
grow: 100,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
buf := dynamoql.NewItemBuffer(tt.size)
assert.Equal(t, 0, buf.Len())
assert.Equal(t, tt.size, buf.Cap())
assert.Empty(t, buf.Items())
if tt.size == 0 {
assert.True(t, buf.IsFull())
} else {
assert.False(t, buf.IsFull())
}
assert.False(t, buf.PeekAt(0))
assert.Nil(t, buf.ItemAt(0))
assert.Nil(t, buf.ItemAt(tt.size+1))
buf.Write(map[string]types.AttributeValue{
"foo": &types.AttributeValueMemberS{Value: "bar"},
})
buf.Grow(tt.grow)
capacity := tt.grow + buf.Len()*2
assert.Equal(t, capacity, buf.Cap())
assert.Equal(t, 1, buf.Len())
buf.WriteItems([]map[string]types.AttributeValue{
{
"foo": &types.AttributeValueMemberS{Value: "bar"},
},
{
"baz": &types.AttributeValueMemberS{Value: "foo"},
},
})
assert.True(t, buf.PeekAt(0))
assert.NotNil(t, buf.ItemAt(0))
buf.Reset()
if tt.size == 0 {
capacity *= 2 // using internal slice allocation
}
assert.Equal(t, capacity, buf.Cap())
assert.Equal(t, 0, buf.Len())
assert.False(t, buf.PeekAt(0))
assert.Nil(t, buf.ItemAt(0))
})
}
}