forked from groovili/go-dynamock-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_item.go
59 lines (43 loc) · 1.38 KB
/
delete_item.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 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 *DeleteItemExpectation) Table(table string) *DeleteItemExpectation {
e.table = &table
return e
}
// WillReturn - method for set desired result
func (e *DeleteItemExpectation) WillReturn(res dynamodb.DeleteItemResponse) *DeleteItemExpectation {
e.output = res.DeleteItemOutput
return e
}
// WithKeys - method for set Keys expectation
func (e *DeleteItemExpectation) WithKeys(keys map[string]dynamodb.AttributeValue) *DeleteItemExpectation {
e.key = keys
return e
}
// DeleteItemRequest - this func will be invoked when test running matching expectation with actual input
func (e *MockDynamoDB) DeleteItemRequest(input *dynamodb.DeleteItemInput) dynamodb.DeleteItemRequest {
req := dynamodb.DeleteItemRequest{
Request: &aws.Request{
HTTPRequest: &http.Request{},
},
}
if len(e.dynaMock.DeleteItemExpect) == 0 {
req.Error = ErrNoExpectation
return req
}
x := e.dynaMock.DeleteItemExpect[0]
validateInput(input, req.Request)
validateTable(input.TableName, x.table, req.Request)
validateKey(input.Key, x.key, req.Request)
if req.Error != nil {
return req
}
e.dynaMock.DeleteItemExpect = append(e.dynaMock.DeleteItemExpect[:0], e.dynaMock.DeleteItemExpect[1:]...)
req.Data = x.output
return req
}