forked from gusaul/go-dynamock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_table.go
64 lines (51 loc) · 1.99 KB
/
create_table.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
package dynamock
import (
"fmt"
"reflect"
"github.com/aws/aws-sdk-go/service/dynamodb"
)
// Name - method for set Name expectation
func (e *CreateTableExpectation) Name(table string) *CreateTableExpectation {
e.table = &table
return e
}
// KeySchema - method for set KeySchema expectation
func (e *CreateTableExpectation) KeySchema(keySchema []*dynamodb.KeySchemaElement) *CreateTableExpectation {
e.keySchema = keySchema
return e
}
// Name - method for set Name expectation
func (e *CreateTableExpectation) ForIndexes(indexes []*dynamodb.GlobalSecondaryIndex) *CreateTableExpectation {
e.globalSecondaryIndexes = indexes
return e
}
// WillReturns - method for set desired result
func (e *CreateTableExpectation) WillReturns(res dynamodb.CreateTableOutput) *CreateTableExpectation {
e.output = &res
return e
}
// CreateTable - this func will be invoked when test running matching expectation with actual input
func (e *MockDynamoDB) CreateTable(input *dynamodb.CreateTableInput) (*dynamodb.CreateTableOutput, error) {
if len(e.dynaMock.CreateTableExpect) > 0 {
x := e.dynaMock.CreateTableExpect[0] //get first element of expectation
if x.table != nil {
if *x.table != *input.TableName {
return nil, fmt.Errorf("Expect table %s but found table %s", *x.table, *input.TableName)
}
}
if x.keySchema != nil {
if !reflect.DeepEqual(x.keySchema, input.KeySchema) {
return nil, fmt.Errorf("Expect keySchema %+v but found keySchema %+v", x.keySchema, input.KeySchema)
}
}
if x.globalSecondaryIndexes != nil {
if !reflect.DeepEqual(x.globalSecondaryIndexes, input.GlobalSecondaryIndexes) {
return nil, fmt.Errorf("Expect secondary indexes %+v but found secondary indexes %+v", x.globalSecondaryIndexes, input.GlobalSecondaryIndexes)
}
}
// delete first element of expectation
e.dynaMock.CreateTableExpect = append(e.dynaMock.CreateTableExpect[:0], e.dynaMock.CreateTableExpect[1:]...)
return x.output, nil
}
return nil, fmt.Errorf("Create Table Expectation Not Found")
}