-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinit.js
59 lines (48 loc) · 1.78 KB
/
init.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright IBM Corp. 2016,2020. All Rights Reserved.
// Node module: loopback-connector-dashdb
// This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-2.0
'use strict';
module.exports = require('should');
const Connector = require('../');
const juggler = require('loopback-datasource-juggler');
let DataSource = juggler.DataSource;
let schemaName, db;
/** these are the env variables in jenkins **/
if (process.env.CI && process.env.PACKAGE_NAME &&
(process.env.BUILD_NUMBER || process.env.BUILD_ID) &&
(process.env.nodeVersion || process.env.node)) {
const buildName = process.env.PACKAGE_NAME.split('-')[2].toUpperCase();
const buildNumber = process.env.BUILD_NUMBER || process.env.BUILD_ID;
const nodeVersion = process.env.nodeVersion || process.env.node;
const os = process.env.OS || process.platform;
schemaName = 'SCHEMA' + buildNumber + '_' + buildName +
'_' + os.toUpperCase() + '_' + nodeVersion;
}
const config = {
username: process.env.DASHDB_USERNAME,
password: process.env.DASHDB_PASSWORD,
hostname: process.env.DASHDB_HOSTNAME || 'localhost',
port: process.env.DASHDB_PORTNUM || 60000,
database: process.env.DASHDB_DATABASE || 'testdb',
schema: schemaName || process.env.DASHDB_SCHEMA || 'STRONGLOOP',
};
global.config = config;
global.getDataSource = global.getSchema = function(options) {
db = new DataSource(Connector, global.config);
db.log = function(a) {
console.log(a);
};
return db;
};
global.resetDataSourceClass = function(ctor) {
DataSource = ctor || juggler.DataSource;
const promise = db ? db.disconnect() : Promise.resolve();
db = undefined;
return promise;
};
global.connectorCapabilities = {
ilike: false,
nilike: false,
};
global.sinon = require('sinon');