-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpaginator_test.go
114 lines (102 loc) · 2.71 KB
/
paginator_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//go:build integration
package dynamoql_test
import (
"context"
"testing"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/maestre3d/dynamoql-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
type queryPaginatorTestSuite struct {
suite.Suite
client *dynamodb.Client
}
func TestNewQueryPaginator(t *testing.T) {
suite.Run(t, &queryPaginatorTestSuite{})
}
func (s *queryPaginatorTestSuite) SetupSuite() {
s.client = newDynamoClient()
}
func (s *queryPaginatorTestSuite) SetupTest() {}
func (s *queryPaginatorTestSuite) TearDownTest() {}
func (s *queryPaginatorTestSuite) TearDownSuite() {}
func (s *queryPaginatorTestSuite) TestQueryPaginator_GetPage() {
tests := []struct {
name string
query dynamodb.QueryInput
pageSize int32
scannedPages uint32
expItems int32
wantErr bool
}{
{
name: "Empty query",
query: dynamodb.QueryInput{}, // missing table
pageSize: 0,
wantErr: true,
},
{
name: "Empty query with table name",
query: dynamoql.NewQueryInput(dynamoql.Select().From("InvoiceAndBills")),
pageSize: 0,
wantErr: true,
},
{
name: "Invalid query",
query: dynamoql.NewQueryInput(dynamoql.Select().From("InvoiceAndBills").Where(dynamoql.Condition{
IsKey: true,
Operator: dynamoql.Equals,
Field: "PK",
Value: dynamoql.NewCompositeKey("I", "1191"),
}, dynamoql.Condition{
IsKey: false,
Operator: dynamoql.Equals,
Field: "SK",
Value: dynamoql.NewCompositeKey("B", ""),
})),
pageSize: 0,
wantErr: true,
},
{
name: "Valid",
query: dynamoql.NewQueryInput(dynamoql.Select().From("InvoiceAndBills").Where(dynamoql.Condition{
IsKey: true,
Operator: dynamoql.Equals,
Field: "PK",
Value: dynamoql.NewCompositeKey("I", "1191"),
}, dynamoql.Condition{
IsKey: true,
Operator: dynamoql.BeginsWith,
Field: "SK",
Value: dynamoql.NewCompositeKey("B", ""),
})),
pageSize: 100,
scannedPages: 1,
expItems: 4,
},
}
for _, tt := range tests {
s.T().Run(tt.name, func(t *testing.T) {
p := dynamoql.NewQueryPaginator(tt.pageSize, s.client, tt.query)
ctx := context.Background()
itemBuf := dynamoql.NewItemBuffer(int(tt.expItems))
for p.Next() {
out, err := p.GetPage(ctx)
require.Equal(t, tt.wantErr, err != nil)
if err != nil {
break
}
itemBuf.WriteItems(out.Items)
if p.Count() >= tt.expItems {
break
}
}
assert.Nil(t, p.NextPageToken())
assert.Equal(t, p.ScannedPages(), tt.scannedPages)
assert.Equal(t, p.Count(), tt.expItems)
assert.Equal(t, itemBuf.Len(), int(tt.expItems))
})
}
}