forked from groovili/go-dynamock-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
describe_table.go
50 lines (37 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
40
41
42
43
44
45
46
47
48
49
50
package dynamock
import (
"net/http"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
)
// Table - method for set Table expectation
func (e *DescribeTableExpectation) Table(table string) *DescribeTableExpectation {
e.table = &table
return e
}
// WillReturn - method for set desired result
func (e *DescribeTableExpectation) WillReturn(res dynamodb.DescribeTableResponse) *DescribeTableExpectation {
e.output = res.DescribeTableOutput
return e
}
// DescribeTableRequest - this func will be invoked when test running matching expectation with actual input
func (e *MockDynamoDB) DescribeTableRequest(input *dynamodb.DescribeTableInput) dynamodb.DescribeTableRequest {
req := dynamodb.DescribeTableRequest{
Request: &aws.Request{
HTTPRequest: &http.Request{},
},
}
if len(e.dynaMock.DescribeTableExpect) == 0 {
req.Error = ErrNoExpectation
return req
}
x := e.dynaMock.DescribeTableExpect[0]
validateInput(input, req.Request)
validateTable(x.table, input.TableName, req.Request)
if req.Error != nil {
return req
}
e.dynaMock.DescribeTableExpect = append(e.dynaMock.DescribeTableExpect[:0], e.dynaMock.DescribeTableExpect[1:]...)
req.Data = x.output
return req
}