-
-
Notifications
You must be signed in to change notification settings - Fork 178
/
createtable_test.go
165 lines (154 loc) · 4.27 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package dynamo
import (
"reflect"
"testing"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
)
type UserAction struct {
UserID string `dynamo:"ID,hash"`
Time time.Time `dynamo:",range"`
Seq int64 `localIndex:"ID-Seq-index,range"`
UUID string
Name string
embeddedWithKeys
}
type embeddedWithKeys struct {
Embedded **[]byte `index:"Embedded-index,hash"`
}
type Metric struct {
ID uint64 `dynamo:"ID,hash"`
Time attributevalue.UnixTime `dynamo:",range"`
Value uint64
}
type Metric2 struct {
ID uint64 `dynamo:"ID,hash"`
Time time.Time `dynamo:",range,unixtime"`
Value uint64
}
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", "Name").
Provision(4, 2).
ProvisionIndex("Embedded-index", 1, 2).
Tag("Tag-Key", "old value").
Tag("Tag-Key", "Tag-Value").
SSEEncryption(true, "alias/key", SSETypeKMS).
input()
expected := &dynamodb.CreateTableInput{
AttributeDefinitions: []types.AttributeDefinition{
{
AttributeName: aws.String("ID"),
AttributeType: types.ScalarAttributeTypeS,
},
{
AttributeName: aws.String("Time"),
AttributeType: types.ScalarAttributeTypeS,
},
{
AttributeName: aws.String("Seq"),
AttributeType: types.ScalarAttributeTypeN,
},
{
AttributeName: aws.String("Embedded"),
AttributeType: types.ScalarAttributeTypeB,
},
},
GlobalSecondaryIndexes: []types.GlobalSecondaryIndex{{
IndexName: aws.String("Embedded-index"),
KeySchema: []types.KeySchemaElement{{
AttributeName: aws.String("Embedded"),
KeyType: types.KeyTypeHash,
}},
Projection: &types.Projection{
ProjectionType: types.ProjectionTypeAll,
},
ProvisionedThroughput: &types.ProvisionedThroughput{
ReadCapacityUnits: aws.Int64(1),
WriteCapacityUnits: aws.Int64(2),
},
}},
KeySchema: []types.KeySchemaElement{{
AttributeName: aws.String("ID"),
KeyType: types.KeyTypeHash,
}, {
AttributeName: aws.String("Time"),
KeyType: types.KeyTypeRange,
}},
LocalSecondaryIndexes: []types.LocalSecondaryIndex{{
IndexName: aws.String("ID-Seq-index"),
KeySchema: []types.KeySchemaElement{{
AttributeName: aws.String("ID"),
KeyType: types.KeyTypeHash,
}, {
AttributeName: aws.String("Seq"),
KeyType: types.KeyTypeRange,
}},
Projection: &types.Projection{
ProjectionType: types.ProjectionTypeInclude,
NonKeyAttributes: []string{"UUID", "Name"},
},
}},
ProvisionedThroughput: &types.ProvisionedThroughput{
ReadCapacityUnits: aws.Int64(4),
WriteCapacityUnits: aws.Int64(2),
},
Tags: []types.Tag{
{
Key: aws.String("Tag-Key"),
Value: aws.String("Tag-Value"),
},
},
SSESpecification: &types.SSESpecification{
Enabled: aws.Bool(true),
KMSMasterKeyId: aws.String("alias/key"),
SSEType: types.SSEType("KMS"),
},
TableName: aws.String("UserActions"),
}
if !reflect.DeepEqual(input, expected) {
t.Error("unexpected input", input)
}
}
func TestCreateTableUintUnixTime(t *testing.T) {
input := testDB.CreateTable("Metrics", Metric{}).
OnDemand(true).
input()
input2 := testDB.CreateTable("Metrics", Metric2{}).
OnDemand(true).
input()
expected := &dynamodb.CreateTableInput{
AttributeDefinitions: []types.AttributeDefinition{
{
AttributeName: aws.String("ID"),
AttributeType: types.ScalarAttributeTypeN,
},
{
AttributeName: aws.String("Time"),
AttributeType: types.ScalarAttributeTypeN,
},
},
KeySchema: []types.KeySchemaElement{{
AttributeName: aws.String("ID"),
KeyType: types.KeyTypeHash,
}, {
AttributeName: aws.String("Time"),
KeyType: types.KeyTypeRange,
}},
BillingMode: types.BillingModePayPerRequest,
TableName: aws.String("Metrics"),
}
if !reflect.DeepEqual(input, expected) {
t.Error("unexpected input", input)
}
if !reflect.DeepEqual(input2, expected) {
t.Error("unexpected input (unixtime tag)", input2)
}
}