-
Notifications
You must be signed in to change notification settings - Fork 1
/
doc_test.go
241 lines (190 loc) · 5.83 KB
/
doc_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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
package sqldb
import (
"context"
"strings"
)
///////////////////////////////////////////////////////////////
type FakeConnectionPool struct {
pingCalls int
pingError error
transactionCalls int
transaction *FakeTransaction
transactionError error
closeCalls int
closeError error
selectCalls int
selectStatement string
selectParameters []interface{}
selectResult *FakeSelectResult
selectError error
executeCalls int
executeStatement string
executeParameters []interface{}
executeResult uint64
executeError error
}
func (this *FakeConnectionPool) Ping(_ context.Context) error {
this.pingCalls++
return this.pingError
}
func (this *FakeConnectionPool) BeginTransaction(_ context.Context) (Transaction, error) {
this.transactionCalls++
return this.transaction, this.transactionError
}
func (this *FakeConnectionPool) Close() error {
this.closeCalls++
return this.closeError
}
func (this *FakeConnectionPool) Execute(_ context.Context, statement string, parameters ...interface{}) (uint64, error) {
this.executeCalls++
this.executeStatement = statement
this.executeParameters = parameters
return this.executeResult, this.executeError
}
func (this *FakeConnectionPool) Select(_ context.Context, statement string, parameters ...interface{}) (SelectResult, error) {
this.selectCalls++
this.selectStatement = statement
this.selectParameters = parameters
return this.selectResult, this.selectError
}
///////////////////////////////////////////////////////////////
type FakeTransaction struct {
commitCalls int
commitError error
rollbackCalls int
rollbackError error
selectCalls int
selectStatement string
selectParameters []interface{}
selectResult *FakeSelectResult
selectError error
executeCalls int
executeStatement string
executeParameters []interface{}
executeResult uint64
executeError error
}
func (this *FakeTransaction) Commit() error {
this.commitCalls++
return this.commitError
}
func (this *FakeTransaction) Rollback() error {
this.rollbackCalls++
return this.rollbackError
}
func (this *FakeTransaction) Execute(_ context.Context, statement string, parameters ...interface{}) (uint64, error) {
this.executeCalls++
this.executeStatement = statement
this.executeParameters = parameters
return this.executeResult, this.executeError
}
func (this *FakeTransaction) Select(_ context.Context, statement string, parameters ...interface{}) (SelectResult, error) {
this.selectCalls++
this.selectStatement = statement
this.selectParameters = parameters
return this.selectResult, this.selectError
}
///////////////////////////////////////////////////////////////
type FakeSelectResult struct {
nextCalls int
errCalls int
closeCalls int
scanCalls int
iterations int
errError error
closeError error
scanError error
}
func (this *FakeSelectResult) Next() bool {
this.nextCalls++
return this.iterations >= this.nextCalls
}
func (this *FakeSelectResult) Err() error {
this.errCalls++
return this.errError
}
func (this *FakeSelectResult) Close() error {
this.closeCalls++
return this.closeError
}
func (this *FakeSelectResult) Scan(_ ...interface{}) error {
this.scanCalls++
return this.scanError
}
///////////////////////////////////////////////////////////////
type FakeExecutor struct {
affected uint64
errorsToReturn []error
statements []string
parameters [][]interface{}
}
func (this *FakeExecutor) Execute(_ context.Context, statement string, parameters ...interface{}) (uint64, error) {
this.statements = append(this.statements, strings.TrimSpace(statement))
this.parameters = append(this.parameters, parameters)
if len(this.statements) <= len(this.errorsToReturn) {
return this.affected, this.errorsToReturn[len(this.statements)-1]
}
return this.affected, nil
}
///////////////////////////////////////////////////////////////
type FakeBindingConnectionPool struct {
pingCalls int
pingError error
transactionCalls int
transaction *FakeBindingTransaction
transactionError error
closeCalls int
closeError error
selectCalls int
selectBinder Binder
selectStatement string
selectParameters []interface{}
selectResult *FakeSelectResult
selectError error
executeCalls int
executeStatement string
executeParameters []interface{}
executeResult uint64
executeError error
}
func (this *FakeBindingConnectionPool) Ping(_ context.Context) error {
this.pingCalls++
return this.pingError
}
func (this *FakeBindingConnectionPool) BeginTransaction(_ context.Context) (BindingTransaction, error) {
this.transactionCalls++
return this.transaction, this.transactionError
}
func (this *FakeBindingConnectionPool) Close() error {
this.closeCalls++
return this.closeError
}
func (this *FakeBindingConnectionPool) Execute(_ context.Context, statement string, parameters ...interface{}) (uint64, error) {
this.executeCalls++
this.executeStatement = statement
this.executeParameters = parameters
return this.executeResult, this.executeError
}
func (this *FakeBindingConnectionPool) BindSelect(_ context.Context, binder Binder, statement string, parameters ...interface{}) error {
this.selectCalls++
this.selectBinder = binder
this.selectStatement = statement
this.selectParameters = parameters
return this.selectError
}
///////////////////////////////////////////////////////////////
type FakeBindingTransaction struct {
}
func (this *FakeBindingTransaction) Commit() error {
panic("Not called")
}
func (this *FakeBindingTransaction) Rollback() error {
panic("Not called")
}
func (this *FakeBindingTransaction) Execute(_ context.Context, _ string, _ ...interface{}) (uint64, error) {
panic("Not called")
}
func (this *FakeBindingTransaction) BindSelect(_ context.Context, _ Binder, _ string, _ ...interface{}) error {
panic("Not called")
}
///////////////////////////////////////////////////////////////