-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers_test.go
159 lines (138 loc) · 3.87 KB
/
helpers_test.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package dynago_test
import (
"reflect"
"testing"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbiface"
)
func assertEq(t *testing.T, want, got interface{}) {
if !reflect.DeepEqual(want, got) {
t.Fatalf("want: %v\n got: %v", want, got)
}
}
type Fatalfer interface {
Fatalf(format string, args ...any)
}
type ddbMock struct {
dynamodbiface.DynamoDBAPI
t Fatalfer
getItemInput *dynamodb.GetItemInput
getItemOutput *dynamodb.GetItemOutput
queryInput *dynamodb.QueryInput
queryOutput *dynamodb.QueryOutput
scanInput *dynamodb.ScanInput
scanOutput *dynamodb.ScanOutput
putItemInput *dynamodb.PutItemInput
deleteItemInput *dynamodb.DeleteItemInput
txWriteInput *dynamodb.TransactWriteItemsInput
updateItemInput *dynamodb.UpdateItemInput
}
func (m *ddbMock) GetItem(i *dynamodb.GetItemInput) (*dynamodb.GetItemOutput, error) {
if !reflect.DeepEqual(i, m.getItemInput) {
m.t.Fatalf("want %v; got %v", m.getItemInput, i)
}
o := *m.getItemOutput
m.getItemInput = nil
m.getItemOutput = nil
return &o, nil
}
func (m *ddbMock) MockGet(i *dynamodb.GetItemInput, o *dynamodb.GetItemOutput) {
m.getItemInput = i
m.getItemOutput = o
}
func (m *ddbMock) MockTransactWriteItems(i *dynamodb.TransactWriteItemsInput) {
m.txWriteInput = i
}
func (m *ddbMock) TransactWriteItems(i *dynamodb.TransactWriteItemsInput) (*dynamodb.TransactWriteItemsOutput, error) {
if !reflect.DeepEqual(i, m.txWriteInput) {
m.t.Fatalf("want %v; got %v", m.txWriteInput, i)
}
m.txWriteInput = nil
return nil, nil
}
func (m *ddbMock) done() {
if m.getItemInput != nil {
m.t.Fatalf("expectations not met")
}
if m.putItemInput != nil {
m.t.Fatalf("expectations not met")
}
if m.deleteItemInput != nil {
m.t.Fatalf("expectations not met")
}
if m.queryInput != nil {
m.t.Fatalf("expectations not met")
}
if m.scanInput != nil {
m.t.Fatalf("expectations not met")
}
if m.getItemOutput != nil {
m.t.Fatalf("expectations not met")
}
if m.txWriteInput != nil {
m.t.Fatalf("expectations not met")
}
if m.updateItemInput != nil {
m.t.Fatalf("expectations not met")
}
}
func (m *ddbMock) PutItem(i *dynamodb.PutItemInput) (*dynamodb.PutItemOutput, error) {
if !reflect.DeepEqual(i, m.putItemInput) {
m.t.Fatalf("want %v; got %v", m.putItemInput, i)
}
m.putItemInput = nil
return nil, nil
}
func (m *ddbMock) MockPut(i *dynamodb.PutItemInput) {
m.putItemInput = i
}
func (m *ddbMock) UpdateItem(i *dynamodb.UpdateItemInput) (*dynamodb.UpdateItemOutput, error) {
if !reflect.DeepEqual(i, m.updateItemInput) {
m.t.Fatalf("want %v; got %v", m.updateItemInput, i)
}
m.updateItemInput = nil
return nil, nil
}
func (m *ddbMock) MockUpdate(i *dynamodb.UpdateItemInput) {
m.updateItemInput = i
}
func (m *ddbMock) DeleteItem(i *dynamodb.DeleteItemInput) (*dynamodb.DeleteItemOutput, error) {
if !reflect.DeepEqual(i, m.deleteItemInput) {
m.t.Fatalf("want %v; got %v", m.deleteItemInput, i)
}
m.deleteItemInput = nil
return nil, nil
}
func (m *ddbMock) MockDelete(i *dynamodb.DeleteItemInput) {
m.deleteItemInput = i
}
func mock(t Fatalfer) *ddbMock {
m := ddbMock{t: t}
return &m
}
func (m *ddbMock) Query(i *dynamodb.QueryInput) (*dynamodb.QueryOutput, error) {
if !reflect.DeepEqual(i, m.queryInput) {
m.t.Fatalf("want %v; got %v", m.queryInput, i)
}
o := *m.queryOutput
m.queryInput = nil
m.queryOutput = nil
return &o, nil
}
func (m *ddbMock) Scan(i *dynamodb.ScanInput) (*dynamodb.ScanOutput, error) {
if !reflect.DeepEqual(i, m.scanInput) {
m.t.Fatalf("want %v; got %v", m.scanInput, i)
}
o := *m.scanOutput
m.scanInput = nil
m.scanOutput = nil
return &o, nil
}
func (m *ddbMock) MockScan(i *dynamodb.ScanInput, o *dynamodb.ScanOutput) {
m.scanInput = i
m.scanOutput = o
}
func (m *ddbMock) MockQuery(i *dynamodb.QueryInput, o *dynamodb.QueryOutput) {
m.queryInput = i
m.queryOutput = o
}