forked from maestre3d/dynamoql-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_builder_test.go
45 lines (42 loc) · 1.28 KB
/
query_builder_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
package dynamoql_test
import (
"testing"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
"github.com/maestre3d/dynamoql"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewQueryBuilder(t *testing.T) {
pageToken := dynamoql.NewPageTokenString("U351c2VyX2lkfjEyMy1hYmMmTn50aW1lc3RhbXBfdW5peH4xMjM=")
b := dynamoql.Select("foo").
From("sample").
Index("sample-gsi").
And().
Negate().
Or(). // replaces And
Where(dynamoql.Condition{
Negate: false,
IsKey: true,
Operator: dynamoql.Equals,
SecondaryOperator: "",
Field: "foo",
Value: "bar",
ExtraValues: nil,
}).
PageToken(pageToken).
StrongConsistency().
OrderBy(dynamoql.Descend).
Limit(10).
DegreeOfParallelism(25).
Metrics(types.ReturnConsumedCapacityIndexes)
out := dynamoql.NewScanInput(b)
require.NotEmpty(t, out)
assert.Equal(t, "sample", *out.TableName)
assert.Equal(t, "sample-gsi", *out.IndexName)
assert.True(t, *out.ConsistentRead)
assert.Equal(t, int32(25), *out.TotalSegments)
assert.Equal(t, int32(10), *out.Limit)
assert.EqualValues(t, pageToken, dynamoql.PageToken(out.ExclusiveStartKey))
outQuery := dynamoql.NewQueryInput(b)
assert.False(t, *outQuery.ScanIndexForward)
}