-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_test.go
83 lines (72 loc) · 1.9 KB
/
handler_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
package dynamodb_test
import (
dynamodb "github.com/sghaida/dyorm"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
var cfg dynamodb.DBConfig
func TestMain(m *testing.M) {
pKey := dynamodb.DBKeyName("partKey")
sKey := dynamodb.DBKeyName("sortKey")
cfg = dynamodb.DBConfig{
TableInfo: dynamodb.DBTableInfo{
TableName: "table",
DBPSKeyNames: dynamodb.DBPSKeyNames{
PartitionKey: pKey,
SortKey: &sKey,
},
},
Indexes: map[dynamodb.DynamoTableOrIndexName]dynamodb.DBPSKeyNames{
"index": {
PartitionKey: pKey,
SortKey: &sKey,
},
},
}
code := m.Run()
os.Exit(code)
}
func TestNewDynamoDB(t *testing.T) {
t.Run("successfully", func(t *testing.T) {
db, _ := dynamodb.NewDynamoDB(cfg)
assert.NotEmpty(t, db)
})
t.Run("missing db table-name", func(t *testing.T) {
pKey := dynamodb.DBKeyName("partKey")
sKey := dynamodb.DBKeyName("sortKey")
cfg := dynamodb.DBConfig{
Indexes: map[dynamodb.DynamoTableOrIndexName]dynamodb.DBPSKeyNames{
"default": {
PartitionKey: pKey,
SortKey: &sKey,
},
},
}
_, err := dynamodb.NewDynamoDB(cfg)
assert.EqualError(t, err, "invalid db config, missing mandatory keys")
})
t.Run("missing table keys", func(t *testing.T) {
cfg := dynamodb.DBConfig{}
_, err := dynamodb.NewDynamoDB(cfg)
assert.EqualError(t, err, "invalid db config, missing mandatory keys")
})
t.Run("missing db index's partition key", func(t *testing.T) {
sKey := dynamodb.DBKeyName("sortKey")
cfg := dynamodb.DBConfig{
TableInfo: dynamodb.DBTableInfo{
TableName: "table",
DBPSKeyNames: dynamodb.DBPSKeyNames{
PartitionKey: dynamodb.DBKeyName("pkey"),
},
},
Indexes: map[dynamodb.DynamoTableOrIndexName]dynamodb.DBPSKeyNames{
"default": {
SortKey: &sKey,
},
},
}
_, err := dynamodb.NewDynamoDB(cfg)
assert.EqualError(t, err, "invalid db config, missing mandatory keys")
})
}