-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysqldbMock.go
270 lines (248 loc) · 6.08 KB
/
mysqldbMock.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
package mysql
import (
"database/sql"
di "github.com/Ulbora/dbinterface"
//"log"
//Required
_ "github.com/go-sql-driver/mysql"
)
//MyDBMock MyDBMock
type MyDBMock struct {
Host string
User string
Password string
Database string
db *sql.DB
err error
MockConnectSuccess bool
MockCloseSuccess bool
MockCommitSuccess bool
MockRollbackSuccess bool
MockInsertSuccess1 bool
MockInsertSuccess2 bool
MockInsertSuccess3 bool
MockInsertSuccess4 bool
MockInsertSuccess5 bool
MockInsertSuccess6 bool
MockInsertSuccess7 bool
MockInsertSuccess8 bool
mockInsertSuccess1Used bool
mockInsertSuccess2Used bool
mockInsertSuccess3Used bool
mockInsertSuccess4Used bool
mockInsertSuccess5Used bool
mockInsertSuccess6Used bool
mockInsertSuccess7Used bool
mockInsertSuccess8Used bool
MockInsertID1 int64
MockInsertID2 int64
MockInsertID3 int64
MockInsertID4 int64
MockInsertID5 int64
MockInsertID6 int64
MockInsertID7 int64
MockInsertID8 int64
MockUpdateSuccess1 bool
MockUpdateSuccess2 bool
MockUpdateSuccess3 bool
MockUpdateSuccess4 bool
mockUpdateSuccess1Used bool
mockUpdateSuccess2Used bool
mockUpdateSuccess3Used bool
mockUpdateSuccess4Used bool
MockDeleteSuccess1 bool
MockDeleteSuccess2 bool
MockDeleteSuccess3 bool
MockDeleteSuccess4 bool
MockDeleteSuccess5 bool
MockDeleteSuccess6 bool
MockDeleteSuccess7 bool
MockDeleteSuccess8 bool
mockDeleteSuccess1Used bool
mockDeleteSuccess2Used bool
mockDeleteSuccess3Used bool
mockDeleteSuccess4Used bool
mockDeleteSuccess5Used bool
mockDeleteSuccess6Used bool
mockDeleteSuccess7Used bool
mockDeleteSuccess8Used bool
MockTestRow *di.DbRow
mockRow1Used bool
mockRow2Used bool
mockRow3Used bool
mockRow4Used bool
mockRow5Used bool
mockRow6Used bool
mockRow7Used bool
mockRow8Used bool
MockRow1 *di.DbRow
MockRow2 *di.DbRow
MockRow3 *di.DbRow
MockRow4 *di.DbRow
MockRow5 *di.DbRow
MockRow6 *di.DbRow
MockRow7 *di.DbRow
MockRow8 *di.DbRow
mockRows1Used bool
mockRows2Used bool
mockRows3Used bool
mockRows4Used bool
mockRows5Used bool
mockRows6Used bool
mockRows7Used bool
mockRows8Used bool
MockRows1 *di.DbRows
MockRows2 *di.DbRows
MockRows3 *di.DbRows
MockRows4 *di.DbRows
MockRows5 *di.DbRows
MockRows6 *di.DbRows
MockRows7 *di.DbRows
MockRows8 *di.DbRows
}
//Connect Connect
func (m *MyDBMock) Connect() bool {
return m.MockConnectSuccess
}
//GetNewDatabase GetNewDatabase
func (m *MyDBMock) GetNewDatabase() di.Database {
var db di.Database
db = m
return db
}
//BeginTransaction BeginTransaction
func (m *MyDBMock) BeginTransaction() di.Transaction {
var trans di.Transaction
var mtx MyDbTxMock
mtx.MyDBMock = m
trans = &mtx
return trans
}
//Test Test
func (m *MyDBMock) Test(query string, args ...interface{}) *di.DbRow {
return m.MockTestRow
}
//Insert Insert
func (m *MyDBMock) Insert(query string, args ...interface{}) (bool, int64) {
var rtn = false
var id int64
if !m.mockInsertSuccess1Used {
m.mockInsertSuccess1Used = true
rtn = m.MockInsertSuccess1
id = m.MockInsertID1
} else if !m.mockInsertSuccess2Used {
m.mockInsertSuccess2Used = true
rtn = m.MockInsertSuccess2
id = m.MockInsertID2
} else if !m.mockInsertSuccess3Used {
m.mockInsertSuccess3Used = true
rtn = m.MockInsertSuccess3
id = m.MockInsertID3
} else if !m.mockInsertSuccess4Used {
m.mockInsertSuccess4Used = true
rtn = m.MockInsertSuccess4
id = m.MockInsertID4
}
return rtn, id
}
//Update Update
func (m *MyDBMock) Update(query string, args ...interface{}) bool {
var rtn = false
if !m.mockUpdateSuccess1Used {
m.mockUpdateSuccess1Used = true
rtn = m.MockUpdateSuccess1
} else if !m.mockUpdateSuccess2Used {
m.mockUpdateSuccess2Used = true
rtn = m.MockUpdateSuccess2
} else if !m.mockUpdateSuccess3Used {
m.mockUpdateSuccess3Used = true
rtn = m.MockUpdateSuccess3
} else if !m.mockUpdateSuccess4Used {
m.mockUpdateSuccess4Used = true
rtn = m.MockUpdateSuccess4
}
return rtn
}
//Get Get
func (m *MyDBMock) Get(query string, args ...interface{}) *di.DbRow {
//return m.MockRow
var rtn *di.DbRow
if !m.mockRow1Used {
m.mockRow1Used = true
rtn = m.MockRow1
} else if !m.mockRow2Used {
m.mockRow2Used = true
rtn = m.MockRow2
} else if !m.mockRow3Used {
m.mockRow3Used = true
rtn = m.MockRow3
} else if !m.mockRow4Used {
m.mockRow4Used = true
rtn = m.MockRow4
} else if !m.mockRow5Used {
m.mockRow5Used = true
rtn = m.MockRow5
} else if !m.mockRow6Used {
m.mockRow6Used = true
rtn = m.MockRow6
} else if !m.mockRow7Used {
m.mockRow7Used = true
rtn = m.MockRow7
} else if !m.mockRow8Used {
m.mockRow8Used = true
rtn = m.MockRow8
}
return rtn
}
//GetList GetList
func (m *MyDBMock) GetList(query string, args ...interface{}) *di.DbRows {
var rtn *di.DbRows
if !m.mockRows1Used {
m.mockRows1Used = true
rtn = m.MockRows1
} else if !m.mockRows2Used {
m.mockRows2Used = true
rtn = m.MockRows2
} else if !m.mockRows3Used {
m.mockRows3Used = true
rtn = m.MockRows3
} else if !m.mockRows4Used {
m.mockRows4Used = true
rtn = m.MockRows4
} else if !m.mockRows5Used {
m.mockRows5Used = true
rtn = m.MockRows5
} else if !m.mockRows6Used {
m.mockRows6Used = true
rtn = m.MockRows6
} else if !m.mockRows7Used {
m.mockRows7Used = true
rtn = m.MockRows7
} else if !m.mockRows8Used {
m.mockRows8Used = true
rtn = m.MockRows8
}
return rtn
}
//Delete Delete
func (m *MyDBMock) Delete(query string, args ...interface{}) bool {
var rtn = false
if !m.mockDeleteSuccess1Used {
m.mockDeleteSuccess1Used = true
rtn = m.MockDeleteSuccess1
} else if !m.mockDeleteSuccess2Used {
m.mockDeleteSuccess2Used = true
rtn = m.MockDeleteSuccess2
} else if !m.mockDeleteSuccess3Used {
m.mockDeleteSuccess3Used = true
rtn = m.MockDeleteSuccess3
} else if !m.mockDeleteSuccess4Used {
m.mockDeleteSuccess4Used = true
rtn = m.MockDeleteSuccess4
}
return rtn
}
//Close Close
func (m *MyDBMock) Close() bool {
return m.MockCloseSuccess
}