-
Notifications
You must be signed in to change notification settings - Fork 51
/
describe_table.go
39 lines (30 loc) · 1.21 KB
/
describe_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
package dynamock
import (
"fmt"
"github.com/aws/aws-sdk-go/service/dynamodb"
)
// Table - method for set Table expectation
func (e *DescribeTableExpectation) Table(table string) *DescribeTableExpectation {
e.table = &table
return e
}
// WillReturns - method for set desired result
func (e *DescribeTableExpectation) WillReturns(res dynamodb.DescribeTableOutput) *DescribeTableExpectation {
e.output = &res
return e
}
// DescribeTable - this func will be invoked when test running matching expectation with actual input
func (e *MockDynamoDB) DescribeTable(input *dynamodb.DescribeTableInput) (*dynamodb.DescribeTableOutput, error) {
if len(e.dynaMock.DescribeTableExpect) > 0 {
x := e.dynaMock.DescribeTableExpect[0] //get first element of expectation
if x.table != nil {
if *x.table != *input.TableName {
return &dynamodb.DescribeTableOutput{}, fmt.Errorf("Expect table %s but found table %s", *x.table, *input.TableName)
}
}
// delete first element of expectation
e.dynaMock.DescribeTableExpect = append(e.dynaMock.DescribeTableExpect[:0], e.dynaMock.DescribeTableExpect[1:]...)
return x.output, nil
}
return &dynamodb.DescribeTableOutput{}, fmt.Errorf("Describe Table Expectation Not Found")
}