@@ -237,50 +237,41 @@ func TestHandlerErrors(t *testing.T) {
237237 lastRowsAffected uint64
238238 }
239239
240+ setupCommands := []string {"CREATE TABLE `test_table` ( `id` INT NOT NULL PRIMARY KEY, `v` INT );" }
241+
240242 tests := []struct {
241243 name string
242- handler * Handler
243- conn * mysql.Conn
244- setup []string
245244 query string
246245 expectedErrorCode int
247246 }{
248247 {
249248 name : "insert with nonexistent field name" ,
250- handler : handler ,
251- conn : dummyConn ,
252- setup : []string {"CREATE TABLE `test_table` ( `id` INT NOT NULL PRIMARY KEY, `v` INT );" },
253249 query : "INSERT INTO `test_table` (`id`, `v_`) VALUES (1, 2)" ,
254250 expectedErrorCode : mysql .ERBadFieldError ,
255251 },
256252 {
257253 name : "insert into nonexistent table" ,
258- handler : handler ,
259- conn : dummyConn ,
260- setup : []string {},
261254 query : "INSERT INTO `test`.`no_such_table` (`id`, `v`) VALUES (1, 2)" ,
262255 expectedErrorCode : mysql .ERNoSuchTable ,
263256 },
264257 {
265258 name : "insert into same column twice" ,
266- handler : handler ,
267- conn : dummyConn ,
268- setup : []string {"CREATE TABLE `test_table` ( `id` INT NOT NULL PRIMARY KEY, `v` INT );" },
269259 query : "INSERT INTO `test`.`test_table` (`id`, `id`, `v`) VALUES (1, 2, 3)" ,
270260 expectedErrorCode : mysql .ERFieldSpecifiedTwice ,
271261 },
272262 }
273263
264+ handler .ComInitDB (dummyConn , "test" )
265+ for _ , setupCommand := range setupCommands {
266+ err := handler .ComQuery (dummyConn , setupCommand , func (res * sqltypes.Result , more bool ) error {
267+ return nil
268+ })
269+ require .NoError (t , err )
270+ }
271+
274272 for _ , test := range tests {
275273 t .Run (test .name , func (t * testing.T ) {
276- handler .ComInitDB (dummyConn , "test" )
277- for _ , setupQuery := range test .setup {
278- err := handler .ComQuery (test .conn , setupQuery , func (res * sqltypes.Result , more bool ) error {
279- return nil
280- })
281- require .NoError (t , err )
282- }
283- err := handler .ComQuery (test .conn , test .query , func (res * sqltypes.Result , more bool ) error {
274+ err := handler .ComQuery (dummyConn , test .query , func (res * sqltypes.Result , more bool ) error {
284275 return nil
285276 })
286277 require .NotNil (t , err )
0 commit comments