forked from guregu/dynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable_test.go
94 lines (83 loc) · 2.79 KB
/
table_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
package dynamo
import (
"fmt"
"reflect"
"testing"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/dynamodb"
)
func TestTableLifecycle(t *testing.T) {
if testDB == nil {
t.Skip(offlineSkipMsg)
}
now := time.Now().UTC()
name := fmt.Sprintf("TestDB-%d", now.UnixNano())
// example from the docs
type UserAction struct {
UserID string `dynamo:"ID,hash" index:"Seq-ID-index,range"`
Time time.Time `dynamo:",range"`
Seq int64 `localIndex:"ID-Seq-index,range" index:"Seq-ID-index,hash"`
UUID string `index:"UUID-index,hash"`
}
// create & wait
if err := testDB.CreateTable(name, UserAction{}).Wait(); err != nil {
t.Fatal(err)
}
// make sure it really works
table := testDB.Table(name)
if err := table.Put(UserAction{UserID: "test", Time: now, Seq: 1, UUID: "42"}).Run(); err != nil {
t.Fatal(err)
}
// delete & wait
if err := testDB.Table(name).DeleteTable().Wait(); err != nil {
t.Fatal(err)
}
}
func TestAddConsumedCapacity(t *testing.T) {
raw := &dynamodb.ConsumedCapacity{
TableName: aws.String("TestTable"),
Table: &dynamodb.Capacity{
CapacityUnits: aws.Float64(9),
ReadCapacityUnits: aws.Float64(4),
WriteCapacityUnits: aws.Float64(5),
},
GlobalSecondaryIndexes: map[string]*dynamodb.Capacity{
"TestGSI": {
CapacityUnits: aws.Float64(3),
ReadCapacityUnits: aws.Float64(1),
WriteCapacityUnits: aws.Float64(2),
},
},
LocalSecondaryIndexes: map[string]*dynamodb.Capacity{
"TestLSI": {
CapacityUnits: aws.Float64(30),
ReadCapacityUnits: aws.Float64(10),
WriteCapacityUnits: aws.Float64(20),
},
},
CapacityUnits: aws.Float64(42),
ReadCapacityUnits: aws.Float64(15),
WriteCapacityUnits: aws.Float64(27),
}
expected := ConsumedCapacity{
TableName: *raw.TableName,
Table: *raw.Table.CapacityUnits,
TableRead: *raw.Table.ReadCapacityUnits,
TableWrite: *raw.Table.WriteCapacityUnits,
GSI: map[string]float64{"TestGSI": *raw.GlobalSecondaryIndexes["TestGSI"].CapacityUnits},
GSIRead: map[string]float64{"TestGSI": *raw.GlobalSecondaryIndexes["TestGSI"].ReadCapacityUnits},
GSIWrite: map[string]float64{"TestGSI": *raw.GlobalSecondaryIndexes["TestGSI"].WriteCapacityUnits},
LSI: map[string]float64{"TestLSI": *raw.LocalSecondaryIndexes["TestLSI"].CapacityUnits},
LSIRead: map[string]float64{"TestLSI": *raw.LocalSecondaryIndexes["TestLSI"].ReadCapacityUnits},
LSIWrite: map[string]float64{"TestLSI": *raw.LocalSecondaryIndexes["TestLSI"].WriteCapacityUnits},
Total: *raw.CapacityUnits,
Read: *raw.ReadCapacityUnits,
Write: *raw.WriteCapacityUnits,
}
var cc ConsumedCapacity
addConsumedCapacity(&cc, raw)
if !reflect.DeepEqual(cc, expected) {
t.Error("bad ConsumedCapacity:", cc, "≠", expected)
}
}