forked from guregu/dynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
table_test.go
59 lines (54 loc) · 1.99 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
package dynamo
import (
"reflect"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/dynamodb"
)
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": &dynamodb.Capacity{
CapacityUnits: aws.Float64(3),
ReadCapacityUnits: aws.Float64(1),
WriteCapacityUnits: aws.Float64(2),
},
},
LocalSecondaryIndexes: map[string]*dynamodb.Capacity{
"TestLSI": &dynamodb.Capacity{
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)
}
}