不要怂,就是干,撸起袖子干!

Commit 2e421712 by Sushant Committed by Mick Hansen

Tests Fixes for MSSQL and upcoming MySQL 5.7, Postgres 9.5 (#6479)

* fixed geom and date parser tests

* ignore warning case for mysql5.7

* check posgis version

* Update data-types.test.js

* mssql test

* mssql logging

* fix mssql

* fix mssql

* build fix

* more change in merge command

* fixed windows 🔥 build
1 parent b0ae95b0
...@@ -130,7 +130,7 @@ ...@@ -130,7 +130,7 @@
"cover-integration": "cross-env COVERAGE=true node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -t 60000 --ui tdd \"test/integration/**/*.test.js\" && node -e \"require('fs').renameSync('coverage/lcov.info', 'coverage/integration.info')\"", "cover-integration": "cross-env COVERAGE=true node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -t 60000 --ui tdd \"test/integration/**/*.test.js\" && node -e \"require('fs').renameSync('coverage/lcov.info', 'coverage/integration.info')\"",
"cover-unit": "cross-env COVERAGE=true node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -t 30000 --ui tdd \"test/unit/**/*.test.js\" && node -e \"require('fs').renameSync('coverage/lcov.info', 'coverage/unit.info')\"", "cover-unit": "cross-env COVERAGE=true node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -t 30000 --ui tdd \"test/unit/**/*.test.js\" && node -e \"require('fs').renameSync('coverage/lcov.info', 'coverage/unit.info')\"",
"merge-coverage": "lcov-result-merger \"coverage/*.info\" \"coverage/lcov.info\"", "merge-coverage": "lcov-result-merger \"coverage/*.info\" \"coverage/lcov.info\"",
"coveralls": "npm run cover && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rimraf ./coverage", "coveralls": "npm run cover && cat ./coverage/lcov.info | node ./node_modules/coveralls/bin/coveralls.js && rimraf ./coverage",
"sscce": "docker-compose run sequelize /bin/sh -c \"node sscce.js\"", "sscce": "docker-compose run sequelize /bin/sh -c \"node sscce.js\"",
"sscce-mysql": "cross-env DIALECT=mysql npm run sscce", "sscce-mysql": "cross-env DIALECT=mysql npm run sscce",
"sscce-postgres": "cross-env DIALECT=postgres npm run sscce", "sscce-postgres": "cross-env DIALECT=postgres npm run sscce",
......
...@@ -12,7 +12,8 @@ var chai = require('chai') ...@@ -12,7 +12,8 @@ var chai = require('chai')
, current = Support.sequelize , current = Support.sequelize
, uuid = require('node-uuid') , uuid = require('node-uuid')
, DataTypes = require('../../lib/data-types') , DataTypes = require('../../lib/data-types')
, dialect = Support.getTestDialect(); , dialect = Support.getTestDialect()
, semver = require('semver');
describe(Support.getTestDialectTeaser('DataTypes'), function() { describe(Support.getTestDialectTeaser('DataTypes'), function() {
afterEach(function () { afterEach(function () {
...@@ -44,14 +45,14 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() { ...@@ -44,14 +45,14 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() {
it('allows me to return values from a custom parse function', function () { it('allows me to return values from a custom parse function', function () {
var parse = Sequelize.DATE.parse = sinon.spy(function (value) { var parse = Sequelize.DATE.parse = sinon.spy(function (value) {
return moment(value, 'YYYY-MM-DD HH:mm:ss Z'); return moment(value, 'YYYY-MM-DD HH:mm:ss');
}); });
var stringify = Sequelize.DATE.prototype.stringify = sinon.spy(function (value, options) { var stringify = Sequelize.DATE.prototype.stringify = sinon.spy(function (value, options) {
if (!moment.isMoment(value)) { if (!moment.isMoment(value)) {
value = this._applyTimezone(value, options); value = this._applyTimezone(value, options);
} }
return value.format('YYYY-MM-DD HH:mm:ss Z'); return value.format('YYYY-MM-DD HH:mm:ss');
}); });
current.refreshTypes(); current.refreshTypes();
...@@ -275,35 +276,55 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() { ...@@ -275,35 +276,55 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() {
}); });
it('should parse an empty GEOMETRY field', function () { it('should parse an empty GEOMETRY field', function () {
var Type = new Sequelize.GEOMETRY(); var Type = new Sequelize.GEOMETRY();
if (current.dialect.supports.GEOMETRY) {
current.refreshTypes();
var User = current.define('user', { field: Type }, { timestamps: false }); // MySQL 5.7 or above doesn't support POINT EMPTY
var point = { type: "Point", coordinates: [] }; if (dialect === 'mysql' && semver.gte(current.options.databaseVersion, '5.7.0')) {
return;
}
return current.sync({ force: true }).then(function () { return new Sequelize.Promise((resolve, reject) => {
return User.create({ if (/^postgres/.test(dialect)) {
//insert a null GEOMETRY type current.query(`SELECT extversion FROM pg_catalog.pg_extension WHERE extname='postgis';`)
field: point .then((result) => {
if (result[0][0] && semver.lte(result[0][0].extversion, '2.1.7')) {
resolve(true);
} else {
resolve();
}
}).catch(reject);
} else {
resolve(true);
}
}).then((runTests) => {
if (current.dialect.supports.GEOMETRY && runTests) {
current.refreshTypes();
var User = current.define('user', { field: Type }, { timestamps: false });
var point = { type: "Point", coordinates: [] };
return current.sync({ force: true }).then(function () {
return User.create({
//insert a null GEOMETRY type
field: point
});
}).then(function () {
//This case throw unhandled exception
return User.findAll();
}).then(function(users){
if (dialect === 'mysql') {
// MySQL will return NULL, becuase they lack EMPTY geometry data support.
expect(users[0].field).to.be.eql(null);
} else if (dialect === 'postgres' || dialect === 'postgres-native') {
//Empty Geometry data [0,0] as per https://trac.osgeo.org/postgis/ticket/1996
expect(users[0].field).to.be.deep.eql({ type: "Point", coordinates: [0,0] });
} else {
expect(users[0].field).to.be.deep.eql(point);
}
}); });
}).then(function () { }
//This case throw unhandled exception });
return User.findAll(); });
}).then(function(users){
if (dialect === 'mysql') {
// MySQL will return NULL, becuase they lack EMPTY geometry data support.
expect(users[0].field).to.be.eql(null);
} else if (dialect === 'postgres' || dialect === 'postgres-native') {
//Empty Geometry data [0,0] as per https://trac.osgeo.org/postgis/ticket/1996
expect(users[0].field).to.be.deep.eql({ type: "Point", coordinates: [0,0] });
} else {
expect(users[0].field).to.be.deep.eql(point);
}
});
}
});
if (dialect === 'postgres' || dialect === 'sqlite') { if (dialect === 'postgres' || dialect === 'sqlite') {
// postgres actively supports IEEE floating point literals, and sqlite doesn't care what we throw at it // postgres actively supports IEEE floating point literals, and sqlite doesn't care what we throw at it
......
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
var chai = require('chai') var chai = require('chai')
, expect = chai.expect , expect = chai.expect
, Support = require(__dirname + '/../support') , Support = require(__dirname + '/../support')
, DataTypes = require(__dirname + '/../../../lib/data-types'); , DataTypes = require(__dirname + '/../../../lib/data-types')
, dialect = Support.getTestDialect()
, semver = require('semver');
var current = Support.sequelize; var current = Support.sequelize;
...@@ -189,23 +191,29 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -189,23 +191,29 @@ describe(Support.getTestDialectTeaser('Model'), function() {
it('should properly escape the single quotes', function () { it('should properly escape the single quotes', function () {
return this.Model.create({ return this.Model.create({
location: { location: {
type: "Point", type: 'Point',
properties: { properties: {
exploit: "'); DELETE YOLO INJECTIONS; -- " exploit: "'); DELETE YOLO INJECTIONS; -- "
}, },
coordinates: [39.807222,-76.984722] coordinates: [39.807222, -76.984722]
} }
}); });
}); });
it('should properly escape the single quotes in coordinates', function () { it('should properly escape the single quotes in coordinates', function () {
// MySQL 5.7, those guys finally fixed this
if (dialect === 'mysql' && semver.gte(this.sequelize.options.databaseVersion, '5.7.0')) {
return;
}
return this.Model.create({ return this.Model.create({
location: { location: {
type: "Point", type: 'Point',
properties: { properties: {
exploit: "'); DELETE YOLO INJECTIONS; -- " exploit: "'); DELETE YOLO INJECTIONS; -- "
}, },
coordinates: [39.807222,"'); DELETE YOLO INJECTIONS; --"] coordinates: [39.807222, "'); DELETE YOLO INJECTIONS; --"]
} }
}); });
}); });
......
...@@ -27,15 +27,21 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() { ...@@ -27,15 +27,21 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
describe('dropAllTables', function() { describe('dropAllTables', function() {
it('should drop all tables', function() { it('should drop all tables', function() {
var self = this; const filterMSSQLDefault = tableNames => tableNames.filter(t => t.tableName !== 'spt_values');
const self = this;
return this.queryInterface.dropAllTables().then(function() { return this.queryInterface.dropAllTables().then(function() {
return self.queryInterface.showAllTables().then(function(tableNames) { return self.queryInterface.showAllTables().then(function(tableNames) {
// MSSQL include spt_values table which is system defined, hence cant be dropped
tableNames = filterMSSQLDefault(tableNames);
expect(tableNames).to.be.empty; expect(tableNames).to.be.empty;
return self.queryInterface.createTable('table', { name: DataTypes.STRING }).then(function() { return self.queryInterface.createTable('table', { name: DataTypes.STRING }).then(function() {
return self.queryInterface.showAllTables().then(function(tableNames) { return self.queryInterface.showAllTables().then(function(tableNames) {
tableNames = filterMSSQLDefault(tableNames);
expect(tableNames).to.have.length(1); expect(tableNames).to.have.length(1);
return self.queryInterface.dropAllTables().then(function() { return self.queryInterface.dropAllTables().then(function() {
return self.queryInterface.showAllTables().then(function(tableNames) { return self.queryInterface.showAllTables().then(function(tableNames) {
// MSSQL include spt_values table which is system defined, hence cant be dropped
tableNames = filterMSSQLDefault(tableNames);
expect(tableNames).to.be.empty; expect(tableNames).to.be.empty;
}); });
}); });
......
...@@ -15,6 +15,7 @@ var chai = require('chai') ...@@ -15,6 +15,7 @@ var chai = require('chai')
, Transaction = require(__dirname + '/../../lib/transaction') , Transaction = require(__dirname + '/../../lib/transaction')
, sinon = require('sinon') , sinon = require('sinon')
, fs = require('fs') , fs = require('fs')
, semver = require('semver')
, current = Support.sequelize; , current = Support.sequelize;
...@@ -267,6 +268,12 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() { ...@@ -267,6 +268,12 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() {
// We can only test MySQL warnings when using MySQL. // We can only test MySQL warnings when using MySQL.
if (dialect === 'mysql') { if (dialect === 'mysql') {
it('logs warnings when there are warnings', function() { it('logs warnings when there are warnings', function() {
// Due to strict MySQL 5.7 all cases below will throw errors rather than warnings
if (semver.gte(current.options.databaseVersion, '5.7.0')) {
return;
}
var logger = sinon.spy(); var logger = sinon.spy();
var sequelize = Support.createSequelizeInstance({ var sequelize = Support.createSequelizeInstance({
logging: logger, logging: logger,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!