forked from groovili/go-dynamock-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_item.go
72 lines (55 loc) · 1.7 KB
/
update_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
60
61
62
63
64
65
66
67
68
69
70
71
72
package dynamock
import (
"net/http"
"reflect"
"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 *UpdateItemExpectation) Table(table string) *UpdateItemExpectation {
e.table = &table
return e
}
// WithKeys - method for set Keys expectation
func (e *UpdateItemExpectation) WithKeys(keys map[string]dynamodb.AttributeValue) *UpdateItemExpectation {
e.key = keys
return e
}
// Updates - method for set Updates expectation
func (e *UpdateItemExpectation) Updates(attrs map[string]dynamodb.AttributeValueUpdate) *UpdateItemExpectation {
e.attributeUpdates = attrs
return e
}
// WillReturn - method for set desired result
func (e *UpdateItemExpectation) WillReturn(res dynamodb.UpdateItemResponse) *UpdateItemExpectation {
e.output = res.UpdateItemOutput
return e
}
// UpdateItemRequest - this func will be invoked when test running matching expectation with actual input
func (e *MockDynamoDB) UpdateItemRequest(input *dynamodb.UpdateItemInput) dynamodb.UpdateItemRequest {
req := dynamodb.UpdateItemRequest{
Request: &aws.Request{
HTTPRequest: &http.Request{},
},
}
if len(e.dynaMock.UpdateItemExpect) == 0 {
req.Error = ErrNoExpectation
return req
}
x := e.dynaMock.UpdateItemExpect[0]
if x.table != nil {
if *x.table != *input.TableName {
req.Error = ErrTableExpectationMismatch
return req
}
}
if x.attributeUpdates != nil {
if !reflect.DeepEqual(x.attributeUpdates, input.AttributeUpdates) {
req.Error = ErrKeyExpectationMismatch
return req
}
}
e.dynaMock.UpdateItemExpect = append(e.dynaMock.UpdateItemExpect[:0], e.dynaMock.UpdateItemExpect[1:]...)
req.Data = x.output
return req
}