@@ -253,8 +253,6 @@ func TestCreateTableAllValuesWithNil(t *testing.T) {
253
253
assert .EqualValues (t , expectedResults , results )
254
254
}
255
255
256
- // TODO the last two
257
-
258
256
func TestCreateTableOk (t * testing.T ) {
259
257
data , mock , err := getMockData ()
260
258
assert .NoError (t , err , "an error was not expected when opening a stub database connection" )
@@ -263,11 +261,17 @@ func TestCreateTableOk(t *testing.T) {
263
261
createTableRows := sqlmock .NewRows ([]string {"Table" , "Create Table" }).
264
262
AddRow ("Test_Table" , "CREATE TABLE 'Test_Table' (`id` int(11) NOT NULL AUTO_INCREMENT,`s` char(60) DEFAULT NULL, PRIMARY KEY (`id`))ENGINE=InnoDB DEFAULT CHARSET=latin1" )
265
263
266
- createTableValueRows := sqlmock .NewRows ([]string {"id" , "email" , "name" }).
264
+ createTableValueCols := sqlmock .NewRows ([]string {"Field" , "Extra" }).
265
+ AddRow ("id" , "" ).
266
+ AddRow ("email" , "" ).
267
+ AddRow ("name" , "" )
268
+
269
+ createTableValueRows := sqlmock .NewRowsWithColumnDefinition (c ("id" , 0 ), c ("email" , "" ), c ("name" , "" )).
267
270
AddRow (1 , nil , "Test Name 1" ).
268
271
AddRow (
2 ,
"[email protected] " ,
"Test Name 2" )
269
272
270
273
mock .ExpectQuery ("^SHOW CREATE TABLE `Test_Table`$" ).WillReturnRows (createTableRows )
274
+ mock .ExpectQuery ("^SHOW COLUMNS FROM `Test_Table`$" ).WillReturnRows (createTableValueCols )
271
275
mock .ExpectQuery ("^SELECT (.+) FROM `Test_Table`$" ).WillReturnRows (createTableValueRows )
272
276
273
277
var buf bytes.Buffer
@@ -300,7 +304,7 @@ CREATE TABLE 'Test_Table' (~id~ int(11) NOT NULL AUTO_INCREMENT,~s~ char(60) DEF
300
304
301
305
LOCK TABLES ~Test_Table~ WRITE;
302
306
/*!40000 ALTER TABLE ~Test_Table~ DISABLE KEYS */;
303
- INSERT INTO ~Test_Table~ VALUES ('1' ,NULL,'Test Name 1'),('2' ,'[email protected] ','Test Name 2');
307
+ INSERT INTO ~Test_Table~ (~id~, ~email~, ~name~) VALUES (1 ,NULL,'Test Name 1'),(2 ,'[email protected] ','Test Name 2');
304
308
/*!40000 ALTER TABLE ~Test_Table~ ENABLE KEYS */;
305
309
UNLOCK TABLES;
306
310
`
@@ -316,11 +320,17 @@ func TestCreateTableOkSmallPackets(t *testing.T) {
316
320
createTableRows := sqlmock .NewRows ([]string {"Table" , "Create Table" }).
317
321
AddRow ("Test_Table" , "CREATE TABLE 'Test_Table' (`id` int(11) NOT NULL AUTO_INCREMENT,`s` char(60) DEFAULT NULL, PRIMARY KEY (`id`))ENGINE=InnoDB DEFAULT CHARSET=latin1" )
318
322
319
- createTableValueRows := sqlmock .NewRows ([]string {"id" , "email" , "name" }).
323
+ createTableValueCols := sqlmock .NewRows ([]string {"Field" , "Extra" }).
324
+ AddRow ("id" , "" ).
325
+ AddRow ("email" , "" ).
326
+ AddRow ("name" , "" )
327
+
328
+ createTableValueRows := sqlmock .NewRowsWithColumnDefinition (c ("id" , 0 ), c ("email" , "" ), c ("name" , "" )).
320
329
AddRow (1 , nil , "Test Name 1" ).
321
330
AddRow (
2 ,
"[email protected] " ,
"Test Name 2" )
322
331
323
332
mock .ExpectQuery ("^SHOW CREATE TABLE `Test_Table`$" ).WillReturnRows (createTableRows )
333
+ mock .ExpectQuery ("^SHOW COLUMNS FROM `Test_Table`$" ).WillReturnRows (createTableValueCols )
324
334
mock .ExpectQuery ("^SELECT (.+) FROM `Test_Table`$" ).WillReturnRows (createTableValueRows )
325
335
326
336
var buf bytes.Buffer
@@ -353,8 +363,8 @@ CREATE TABLE 'Test_Table' (~id~ int(11) NOT NULL AUTO_INCREMENT,~s~ char(60) DEF
353
363
354
364
LOCK TABLES ~Test_Table~ WRITE;
355
365
/*!40000 ALTER TABLE ~Test_Table~ DISABLE KEYS */;
356
- INSERT INTO ~Test_Table~ VALUES ('1' ,NULL,'Test Name 1');
357
- INSERT INTO ~Test_Table~ VALUES ('2' ,'[email protected] ','Test Name 2');
366
+ INSERT INTO ~Test_Table~ (~id~, ~email~, ~name~) VALUES (1 ,NULL,'Test Name 1');
367
+ INSERT INTO ~Test_Table~ (~id~, ~email~, ~name~) VALUES (2 ,'[email protected] ','Test Name 2');
358
368
/*!40000 ALTER TABLE ~Test_Table~ ENABLE KEYS */;
359
369
UNLOCK TABLES;
360
370
`
0 commit comments