forked from guregu/dynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createtable_test.go
100 lines (92 loc) · 2.53 KB
/
createtable_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
package dynamo
import (
"reflect"
"testing"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/dynamodb"
)
type UserAction struct {
UserID string `dynamo:"ID,hash"`
Time time.Time `dynamo:",range"`
Seq int64 `localIndex:"ID-Seq-index,range"`
UUID string
embeddedWithKeys
}
type embeddedWithKeys struct {
Embedded **[]byte `index:"Embedded-index,hash"`
}
func TestCreateTable(t *testing.T) {
// until I do DeleteTable let's just compare the input
// if testDB == nil {
// t.Skip(offlineSkipMsg)
// }
input := testDB.CreateTable("UserActions", UserAction{}).
Project("ID-Seq-index", IncludeProjection, "UUID").
Provision(4, 2).
ProvisionIndex("Embedded-index", 1, 2).
input()
expected := &dynamodb.CreateTableInput{
AttributeDefinitions: []*dynamodb.AttributeDefinition{
{
AttributeName: aws.String("ID"),
AttributeType: aws.String("S"),
},
{
AttributeName: aws.String("Time"),
AttributeType: aws.String("S"),
},
{
AttributeName: aws.String("Seq"),
AttributeType: aws.String("N"),
},
{
AttributeName: aws.String("Embedded"),
AttributeType: aws.String("B"),
},
},
GlobalSecondaryIndexes: []*dynamodb.GlobalSecondaryIndex{{
IndexName: aws.String("Embedded-index"),
KeySchema: []*dynamodb.KeySchemaElement{{
AttributeName: aws.String("Embedded"),
KeyType: aws.String("HASH"),
}},
Projection: &dynamodb.Projection{
ProjectionType: aws.String("ALL"),
},
ProvisionedThroughput: &dynamodb.ProvisionedThroughput{
ReadCapacityUnits: aws.Int64(1),
WriteCapacityUnits: aws.Int64(2),
},
}},
KeySchema: []*dynamodb.KeySchemaElement{{
AttributeName: aws.String("ID"),
KeyType: aws.String("HASH"),
}, {
AttributeName: aws.String("Time"),
KeyType: aws.String("RANGE"),
}},
LocalSecondaryIndexes: []*dynamodb.LocalSecondaryIndex{{
IndexName: aws.String("ID-Seq-index"),
KeySchema: []*dynamodb.KeySchemaElement{{
AttributeName: aws.String("ID"),
KeyType: aws.String("HASH"),
}, {
AttributeName: aws.String("Seq"),
KeyType: aws.String("RANGE"),
}},
Projection: &dynamodb.Projection{
ProjectionType: aws.String("INCLUDE"),
NonKeyAttributes: []*string{aws.String("UUID")},
},
}},
ProvisionedThroughput: &dynamodb.ProvisionedThroughput{
ReadCapacityUnits: aws.Int64(4),
WriteCapacityUnits: aws.Int64(2),
},
TableName: aws.String("UserActions"),
}
if !reflect.DeepEqual(input, expected) {
t.Error("unexpected input", input)
}
}