2016-05-03 23:52:03 +00:00
|
|
|
// Copyright IBM Corp. 2013,2016. All Rights Reserved.
|
|
|
|
// Node module: loopback-connector-mysql
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
2016-08-09 20:29:47 +00:00
|
|
|
// TODO: used for testing support for parallel testing on ci.strongloop.com which
|
|
|
|
// provides MYSQL_* env vars instead of TEST_MYSQL_* env vars.
|
|
|
|
process.env.TEST_MYSQL_USER = process.env.TEST_MYSQL_USER || process.env.MYSQL_USER;
|
|
|
|
process.env.TEST_MYSQL_PASSWORD = process.env.TEST_MYSQL_PASSWORD || process.env.MYSQL_PASSWORD;
|
|
|
|
process.env.TEST_MYSQL_HOST = process.env.TEST_MYSQL_HOST || process.env.MYSQL_HOST;
|
|
|
|
process.env.TEST_MYSQL_PORT = process.env.TEST_MYSQL_PORT || process.env.MYSQL_PORT;
|
|
|
|
|
2013-04-07 21:53:55 +00:00
|
|
|
module.exports = require('should');
|
|
|
|
|
2013-08-22 04:53:48 +00:00
|
|
|
var DataSource = require('loopback-datasource-juggler').DataSource;
|
|
|
|
|
2013-08-23 21:31:43 +00:00
|
|
|
var config = require('rc')('loopback', {test: {mysql: {}}}).test.mysql;
|
2015-11-18 22:37:46 +00:00
|
|
|
console.log(config)
|
2014-02-13 00:57:06 +00:00
|
|
|
global.getConfig = function (options) {
|
|
|
|
|
|
|
|
var dbConf = {
|
2015-11-19 01:13:06 +00:00
|
|
|
host: process.env.TEST_MYSQL_HOST || config.host || 'localhost',
|
|
|
|
port: process.env.TEST_MYSQL_PORT || config.port || 3306,
|
2014-02-13 00:57:06 +00:00
|
|
|
database: 'myapp_test',
|
2015-11-19 01:13:06 +00:00
|
|
|
username: process.env.TEST_MYSQL_USER || config.username,
|
|
|
|
password: process.env.TEST_MYSQL_PASSWORD || config.password,
|
2014-02-13 00:57:06 +00:00
|
|
|
createDatabase: true
|
|
|
|
};
|
|
|
|
|
|
|
|
if (options) {
|
|
|
|
for (var el in options) {
|
|
|
|
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
|
|
|
|
2014-02-13 00:57:06 +00:00
|
|
|
global.getDataSource = global.getSchema = function (options) {
|
|
|
|
var db = new DataSource(require('../'), getConfig(options));
|
|
|
|
return db;
|
2013-03-27 00:37:13 +00:00
|
|
|
};
|
2013-07-22 00:27:54 +00:00
|
|
|
|
2015-07-21 04:50:47 +00:00
|
|
|
global.sinon = require('sinon');
|