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:
Ryan Graham 2016-08-04 19:20:42 -07:00
parent 45491d1d90
commit b965a31f77
No known key found for this signature in database
GPG Key ID: F15A82CDEFD85858
2 changed files with 25 additions and 11 deletions

View File

@ -7,6 +7,7 @@ require('./init.js');
var assert = require('assert'); var assert = require('assert');
var db, EnumModel, ANIMAL_ENUM; var db, EnumModel, ANIMAL_ENUM;
var mysqlVersion;
describe('MySQL specific datatypes', function () { describe('MySQL specific datatypes', function () {
@ -43,6 +44,11 @@ describe('MySQL specific datatypes', function () {
}); });
it('should fail spectacularly with invalid enum values', function (done) { 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) { var em = EnumModel.create({animal: 'horse', condition: 'sleepy', mood: 'happy'}, function (err, obj) {
assert.ok(!err); assert.ok(!err);
EnumModel.findById(obj.id, function (err, found) { EnumModel.findById(obj.id, function (err, found) {
@ -95,8 +101,10 @@ function setup(done) {
extras: 'JSON' 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) { var query = function (sql, cb) {

View File

@ -8,6 +8,7 @@ var assert = require('assert');
var Schema = require('loopback-datasource-juggler').Schema; var Schema = require('loopback-datasource-juggler').Schema;
var db, UserData, StringData, NumberData, DateData; var db, UserData, StringData, NumberData, DateData;
var mysqlVersion;
describe('migrations', function () { describe('migrations', function () {
@ -93,7 +94,6 @@ describe('migrations', function () {
Packed: null, Packed: null,
Null: '', Null: '',
Index_type: 'BTREE', Index_type: 'BTREE',
Index_comment: '',
Comment: '' }, Comment: '' },
email: { email: {
Table: /UserData/i, Table: /UserData/i,
@ -102,12 +102,11 @@ describe('migrations', function () {
Seq_in_index: 1, Seq_in_index: 1,
Column_name: 'email', Column_name: 'email',
Collation: 'A', Collation: 'A',
Cardinality: 0, Cardinality: /^5\.7/.test(mysqlVersion) ? 0 : null,
Sub_part: null, Sub_part: /^5\.7/.test(mysqlVersion) ? null : 333,
Packed: null, Packed: null,
Null: '', Null: '',
Index_type: 'BTREE', Index_type: 'BTREE',
Index_comment: '',
Comment: '' }, Comment: '' },
index0: { index0: {
Table: /UserData/i, Table: /UserData/i,
@ -116,12 +115,11 @@ describe('migrations', function () {
Seq_in_index: 1, Seq_in_index: 1,
Column_name: 'email', Column_name: 'email',
Collation: 'A', Collation: 'A',
Cardinality: 0, Cardinality: /^5\.7/.test(mysqlVersion) ? 0 : null,
Sub_part: null, Sub_part: /^5\.7/.test(mysqlVersion) ? null : 333,
Packed: null, Packed: null,
Null: '', Null: '',
Index_type: 'BTREE', Index_type: 'BTREE',
Index_comment: '',
Comment: '' } Comment: '' }
}); });
done(); done();
@ -294,6 +292,12 @@ describe('migrations', function () {
}); });
it('should allow numbers with decimals', function (done) { 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, NumberData.create({number: 1.1234567, tinyInt: 123456, mediumInt: -1234567,
floater: 123456789.1234567 }, function (err, obj) { floater: 123456789.1234567 }, function (err, obj) {
assert.ok(!err); assert.ok(!err);
@ -388,8 +392,10 @@ function setup(done) {
timestamp: {type: Date, dataType: 'timestamp'} 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) { var query = function (sql, cb) {