2020-02-08 22:23:33 +00:00
|
|
|
// Copyright IBM Corp. 2013,2019. All Rights Reserved.
|
2016-05-03 23:52:03 +00:00
|
|
|
// Node module: loopback-connector-mysql
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
2016-08-10 18:41:03 +00:00
|
|
|
'use strict';
|
2016-08-09 20:29:47 +00:00
|
|
|
|
2013-04-07 21:53:55 +00:00
|
|
|
module.exports = require('should');
|
2019-06-28 14:54:45 +00:00
|
|
|
const juggler = require('loopback-datasource-juggler');
|
|
|
|
let DataSource = juggler.DataSource;
|
2013-08-22 04:53:48 +00:00
|
|
|
|
2020-08-28 06:43:09 +00:00
|
|
|
const config = require('rc')('loopback', {test: {mysql: {}}}).test.mysql;
|
2016-08-10 18:41:03 +00:00
|
|
|
global.getConfig = function(options) {
|
2020-08-28 06:43:09 +00:00
|
|
|
const dbConf = {
|
2021-04-11 03:07:56 +00:00
|
|
|
host: process.env.MYSQL_HOST || config.host || 'localhost',
|
2021-04-12 02:32:08 +00:00
|
|
|
port: process.env.MYSQL_PORT || config.port || 3306,
|
2021-02-18 16:02:59 +00:00
|
|
|
database: process.env.MYSQL_DATABASE || 'testdb',
|
2021-04-11 03:07:56 +00:00
|
|
|
username: process.env.MYSQL_USER || config.username || 'root',
|
|
|
|
password: process.env.MYSQL_PASSWORD || config.password || 'root',
|
2016-08-10 18:41:03 +00:00
|
|
|
createDatabase: true,
|
2014-02-13 00:57:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (options) {
|
2020-08-28 06:43:09 +00:00
|
|
|
for (const el in options) {
|
2014-02-13 00:57:06 +00:00
|
|
|
dbConf[el] = options[el];
|
2013-07-22 00:27:54 +00:00
|
|
|
}
|
2014-02-13 00:57:06 +00:00
|
|
|
}
|
|
|
|
return dbConf;
|
2013-08-23 21:31:43 +00:00
|
|
|
};
|
2013-07-22 00:27:54 +00:00
|
|
|
|
2019-06-28 14:54:45 +00:00
|
|
|
let db;
|
|
|
|
global.getDataSource = global.getSchema = function(options, customClass) {
|
|
|
|
const ctor = customClass || DataSource;
|
|
|
|
db = new ctor(require('../'), global.getConfig(options));
|
|
|
|
db.log = function(a) {
|
|
|
|
console.log(a);
|
|
|
|
};
|
2014-02-13 00:57:06 +00:00
|
|
|
return db;
|
2013-03-27 00:37:13 +00:00
|
|
|
};
|
2013-07-22 00:27:54 +00:00
|
|
|
|
2019-06-28 14:54:45 +00:00
|
|
|
global.resetDataSourceClass = function(ctor) {
|
|
|
|
DataSource = ctor || juggler.DataSource;
|
|
|
|
const promise = db ? db.disconnect() : Promise.resolve();
|
|
|
|
db = undefined;
|
|
|
|
return promise;
|
|
|
|
};
|
|
|
|
|
2016-10-12 06:13:20 +00:00
|
|
|
global.connectorCapabilities = {
|
|
|
|
ilike: false,
|
|
|
|
nilike: false,
|
|
|
|
};
|
|
|
|
|
2015-07-21 04:50:47 +00:00
|
|
|
global.sinon = require('sinon');
|