test: account for mysql version differences
Some of the tests are based on default behaviour of MySQL 5.5 or older which is not the same as 5.7 out of the box.
This commit is contained in:
parent
45491d1d90
commit
b965a31f77
|
@ -7,6 +7,7 @@ require('./init.js');
|
|||
var assert = require('assert');
|
||||
|
||||
var db, EnumModel, ANIMAL_ENUM;
|
||||
var mysqlVersion;
|
||||
|
||||
describe('MySQL specific datatypes', function () {
|
||||
|
||||
|
@ -43,6 +44,11 @@ describe('MySQL specific datatypes', function () {
|
|||
});
|
||||
|
||||
it('should fail spectacularly with invalid enum values', function (done) {
|
||||
// TODO: with a default install of MySQL 5.7, these queries actually do fail and raise errors...
|
||||
if (/^5\.7/.test(mysqlVersion)) {
|
||||
assert.ok(mysqlVersion, 'skipping decimal/number test on mysql 5.7');
|
||||
return done();
|
||||
}
|
||||
var em = EnumModel.create({animal: 'horse', condition: 'sleepy', mood: 'happy'}, function (err, obj) {
|
||||
assert.ok(!err);
|
||||
EnumModel.findById(obj.id, function (err, found) {
|
||||
|
@ -95,8 +101,10 @@ function setup(done) {
|
|||
extras: 'JSON'
|
||||
});
|
||||
|
||||
blankDatabase(db, done);
|
||||
|
||||
query('SELECT VERSION()', function(err, res) {
|
||||
mysqlVersion = res && res[0] && res[0]['VERSION()'];
|
||||
blankDatabase(db, done);
|
||||
});
|
||||
}
|
||||
|
||||
var query = function (sql, cb) {
|
||||
|
|
|
@ -8,6 +8,7 @@ var assert = require('assert');
|
|||
var Schema = require('loopback-datasource-juggler').Schema;
|
||||
|
||||
var db, UserData, StringData, NumberData, DateData;
|
||||
var mysqlVersion;
|
||||
|
||||
describe('migrations', function () {
|
||||
|
||||
|
@ -93,7 +94,6 @@ describe('migrations', function () {
|
|||
Packed: null,
|
||||
Null: '',
|
||||
Index_type: 'BTREE',
|
||||
Index_comment: '',
|
||||
Comment: '' },
|
||||
email: {
|
||||
Table: /UserData/i,
|
||||
|
@ -102,12 +102,11 @@ describe('migrations', function () {
|
|||
Seq_in_index: 1,
|
||||
Column_name: 'email',
|
||||
Collation: 'A',
|
||||
Cardinality: 0,
|
||||
Sub_part: null,
|
||||
Cardinality: /^5\.7/.test(mysqlVersion) ? 0 : null,
|
||||
Sub_part: /^5\.7/.test(mysqlVersion) ? null : 333,
|
||||
Packed: null,
|
||||
Null: '',
|
||||
Index_type: 'BTREE',
|
||||
Index_comment: '',
|
||||
Comment: '' },
|
||||
index0: {
|
||||
Table: /UserData/i,
|
||||
|
@ -116,12 +115,11 @@ describe('migrations', function () {
|
|||
Seq_in_index: 1,
|
||||
Column_name: 'email',
|
||||
Collation: 'A',
|
||||
Cardinality: 0,
|
||||
Sub_part: null,
|
||||
Cardinality: /^5\.7/.test(mysqlVersion) ? 0 : null,
|
||||
Sub_part: /^5\.7/.test(mysqlVersion) ? null : 333,
|
||||
Packed: null,
|
||||
Null: '',
|
||||
Index_type: 'BTREE',
|
||||
Index_comment: '',
|
||||
Comment: '' }
|
||||
});
|
||||
done();
|
||||
|
@ -294,6 +292,12 @@ describe('migrations', function () {
|
|||
});
|
||||
|
||||
it('should allow numbers with decimals', function (done) {
|
||||
// TODO: Default install of MySQL 5.7 returns an error here, which we assert should not happen.
|
||||
if (/^5\.7/.test(mysqlVersion)) {
|
||||
assert.ok(mysqlVersion, 'skipping decimal/number test on mysql 5.7');
|
||||
return done();
|
||||
}
|
||||
|
||||
NumberData.create({number: 1.1234567, tinyInt: 123456, mediumInt: -1234567,
|
||||
floater: 123456789.1234567 }, function (err, obj) {
|
||||
assert.ok(!err);
|
||||
|
@ -388,8 +392,10 @@ function setup(done) {
|
|||
timestamp: {type: Date, dataType: 'timestamp'}
|
||||
});
|
||||
|
||||
blankDatabase(db, done);
|
||||
|
||||
query('SELECT VERSION()', function(err, res) {
|
||||
mysqlVersion = res && res[0] && res[0]['VERSION()'];
|
||||
blankDatabase(db, done);
|
||||
});
|
||||
}
|
||||
|
||||
var query = function (sql, cb) {
|
||||
|
|
Loading…
Reference in New Issue