Skip to content

Commit 2d27ffa

Browse files
committed
fix all tests
1 parent d3b28b3 commit 2d27ffa

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

dump_test.go

+17-7
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,6 @@ func TestCreateTableAllValuesWithNil(t *testing.T) {
253253
assert.EqualValues(t, expectedResults, results)
254254
}
255255

256-
// TODO the last two
257-
258256
func TestCreateTableOk(t *testing.T) {
259257
data, mock, err := getMockData()
260258
assert.NoError(t, err, "an error was not expected when opening a stub database connection")
@@ -263,11 +261,17 @@ func TestCreateTableOk(t *testing.T) {
263261
createTableRows := sqlmock.NewRows([]string{"Table", "Create Table"}).
264262
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")
265263

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", "")).
267270
AddRow(1, nil, "Test Name 1").
268271
AddRow(2, "[email protected]", "Test Name 2")
269272

270273
mock.ExpectQuery("^SHOW CREATE TABLE `Test_Table`$").WillReturnRows(createTableRows)
274+
mock.ExpectQuery("^SHOW COLUMNS FROM `Test_Table`$").WillReturnRows(createTableValueCols)
271275
mock.ExpectQuery("^SELECT (.+) FROM `Test_Table`$").WillReturnRows(createTableValueRows)
272276

273277
var buf bytes.Buffer
@@ -300,7 +304,7 @@ CREATE TABLE 'Test_Table' (~id~ int(11) NOT NULL AUTO_INCREMENT,~s~ char(60) DEF
300304
301305
LOCK TABLES ~Test_Table~ WRITE;
302306
/*!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');
304308
/*!40000 ALTER TABLE ~Test_Table~ ENABLE KEYS */;
305309
UNLOCK TABLES;
306310
`
@@ -316,11 +320,17 @@ func TestCreateTableOkSmallPackets(t *testing.T) {
316320
createTableRows := sqlmock.NewRows([]string{"Table", "Create Table"}).
317321
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")
318322

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", "")).
320329
AddRow(1, nil, "Test Name 1").
321330
AddRow(2, "[email protected]", "Test Name 2")
322331

323332
mock.ExpectQuery("^SHOW CREATE TABLE `Test_Table`$").WillReturnRows(createTableRows)
333+
mock.ExpectQuery("^SHOW COLUMNS FROM `Test_Table`$").WillReturnRows(createTableValueCols)
324334
mock.ExpectQuery("^SELECT (.+) FROM `Test_Table`$").WillReturnRows(createTableValueRows)
325335

326336
var buf bytes.Buffer
@@ -353,8 +363,8 @@ CREATE TABLE 'Test_Table' (~id~ int(11) NOT NULL AUTO_INCREMENT,~s~ char(60) DEF
353363
354364
LOCK TABLES ~Test_Table~ WRITE;
355365
/*!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');
358368
/*!40000 ALTER TABLE ~Test_Table~ ENABLE KEYS */;
359369
UNLOCK TABLES;
360370
`

0 commit comments

Comments
 (0)