loopback-bluemix
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -146,10 +146,13 @@ // Copyright IBM Corp. 2017. All Rights Reserved. | ||
/** | ||
* Load ~/.cf/config.json | ||
* @returns {*} | ||
* Load Cloud Foundry config file | ||
* @param configFilePath {string} Path to CF config file | ||
* @returns {object} | ||
*/ | ||
function getCfConfig() { | ||
var home = os.homedir(); | ||
var cfConfig = {}; | ||
function getCfConfig(configFilePath) { | ||
if (!configFilePath) { | ||
var home = os.homedir(); | ||
configFilePath = path.join(home, '.cf', 'config.json'); | ||
} | ||
try { | ||
cfConfig = require(path.join(home, '.cf/config.json')); | ||
var cfConfig = require(configFilePath); | ||
} catch (e) { | ||
@@ -419,3 +422,2 @@ console.error('Please use `cf login` to log into Bluemix first.'); | ||
/** | ||
@@ -422,0 +424,0 @@ * Bind a service to an app |
{ | ||
"name": "loopback-bluemix", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Utilities for generating generate Bluemix artefacts", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -21,67 +21,79 @@ // Copyright IBM Corp. 2014,2016. All Rights Reserved. | ||
var cf = lbBM.cf; | ||
var accessToken = cf.getCfConfig().accessToken; | ||
var cfConfig = cf.getCfConfig(); | ||
describe('lib/cf', function() { | ||
it('should get apps', function(done) { | ||
cf.getApps(null, accessToken, function(err, apps) { | ||
assert(!err); | ||
var appFound = false; | ||
apps.forEach(function(app) { | ||
if (cfTestConfig.app.name === app.entity.name) { | ||
appFound = true; | ||
} | ||
if (Object.keys(cfConfig).length) { | ||
var accessToken = cfConfig.accessToken; | ||
describe('lib/cf', function() { | ||
it('should get CF config', function() { | ||
var cfConfig = cf.getCfConfig(); | ||
assert('organization' in cfConfig); | ||
assert('space' in cfConfig); | ||
assert('apiURL' in cfConfig); | ||
assert('accessToken' in cfConfig); | ||
}); | ||
it('should get apps', function(done) { | ||
cf.getApps(null, accessToken, function(err, apps) { | ||
assert(!err); | ||
var appFound = false; | ||
apps.forEach(function(app) { | ||
if (cfTestConfig.app.name === app.entity.name) { | ||
appFound = true; | ||
} | ||
}); | ||
assert(appFound); | ||
done(); | ||
}); | ||
assert(appFound); | ||
done(); | ||
}); | ||
}); | ||
it('should get service instances', function(done) { | ||
cf.getServiceInstances(null, accessToken, function(err, services) { | ||
assert(!err); | ||
var state = getServiceState(services); | ||
assert(state.supportedServiceFound); | ||
assert(state.unsupportedServiceFound); | ||
assert(state.nondataServiceFound); | ||
done(); | ||
it('should get service instances', function(done) { | ||
cf.getServiceInstances(null, accessToken, function(err, services) { | ||
assert(!err); | ||
var state = getServiceState(services); | ||
assert(state.supportedServiceFound); | ||
assert(state.unsupportedServiceFound); | ||
assert(state.nondataServiceFound); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('should get only data service instances', function(done) { | ||
cf.getDataServiceInstances(null, accessToken, function(err, services) { | ||
assert(!err); | ||
var state = getServiceState(services); | ||
assert(state.supportedServiceFound); | ||
assert(state.unsupportedServiceFound); | ||
assert(!state.nondataServiceFound); | ||
done(); | ||
it('should get only data service instances', function(done) { | ||
cf.getDataServiceInstances(null, accessToken, function(err, services) { | ||
assert(!err); | ||
var state = getServiceState(services); | ||
assert(state.supportedServiceFound); | ||
assert(state.unsupportedServiceFound); | ||
assert(!state.nondataServiceFound); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
function getServiceState(services) { | ||
var state = { | ||
supportedServiceFound: false, | ||
unsupportedServiceFound: false, | ||
nondataServiceFound: false, | ||
}; | ||
function getServiceState(services) { | ||
var state = { | ||
supportedServiceFound: false, | ||
unsupportedServiceFound: false, | ||
nondataServiceFound: false, | ||
}; | ||
services.forEach(function(service) { | ||
var supportedService = cfTestConfig.service.supported; | ||
var unsupportedService = cfTestConfig.service.unsupported; | ||
var nondataService = cfTestConfig.service.nondata; | ||
var serviceName = service.instance.entity.name; | ||
var serviceGuid = service.instance.metadata.guid; | ||
if (supportedService.name === serviceName && | ||
supportedService.guid === serviceGuid) { | ||
state.supportedServiceFound = true; | ||
} else if (unsupportedService.name === serviceName && | ||
unsupportedService.guid === serviceGuid) { | ||
state.unsupportedServiceFound = true; | ||
} else if (nondataService.name === serviceName && | ||
nondataService.guid === serviceGuid) { | ||
state.nondataServiceFound = true; | ||
} | ||
}); | ||
return state; | ||
services.forEach(function(service) { | ||
var supportedService = cfTestConfig.service.supported; | ||
var unsupportedService = cfTestConfig.service.unsupported; | ||
var nondataService = cfTestConfig.service.nondata; | ||
var serviceName = service.instance.entity.name; | ||
var serviceGuid = service.instance.metadata.guid; | ||
if (supportedService.name === serviceName && | ||
supportedService.guid === serviceGuid) { | ||
state.supportedServiceFound = true; | ||
} else if (unsupportedService.name === serviceName && | ||
unsupportedService.guid === serviceGuid) { | ||
state.unsupportedServiceFound = true; | ||
} else if (nondataService.name === serviceName && | ||
nondataService.guid === serviceGuid) { | ||
state.nondataServiceFound = true; | ||
} | ||
}); | ||
return state; | ||
} | ||
} |
@@ -15,2 +15,3 @@ // Copyright IBM Corp. 2014,2016. All Rights Reserved. | ||
var lbBM = require(path.resolve(__dirname, '..')); | ||
var cfConfig = lbBM.cf.getCfConfig(); | ||
var sandboxDir = path.resolve(__dirname, 'sandbox'); | ||
@@ -79,17 +80,19 @@ var fixturesDir = path.resolve(__dirname, 'fixtures'); | ||
it('should configure a Bluemix datasource selection', function(done) { | ||
datasource.async = function() { | ||
return function() { | ||
assert('cloudant-service' === datasource.name); | ||
assert('cloudant' === datasource.connector); | ||
assert('serviceGUID' in datasource); | ||
done(); | ||
if (Object.keys(cfConfig).length) { | ||
it('should configure a Bluemix datasource selection', function(done) { | ||
datasource.async = function() { | ||
return function() { | ||
assert('cloudant-service' === datasource.name); | ||
assert('cloudant' === datasource.connector); | ||
assert('serviceGUID' in datasource); | ||
done(); | ||
}; | ||
}; | ||
}; | ||
datasource.log = console.log; | ||
datasource.prompt = generatePrompt({ | ||
serviceName: 'cloudant-service', | ||
datasource.log = console.log; | ||
datasource.prompt = generatePrompt({ | ||
serviceName: 'cloudant-service', | ||
}); | ||
lbBM.ds.selectBluemixDatasource(datasource, globalize); | ||
}); | ||
lbBM.ds.selectBluemixDatasource(datasource, globalize); | ||
}); | ||
} | ||
@@ -111,11 +114,13 @@ it('should configure new service provision', function(done) { | ||
it('should get service plans', function(done) { | ||
datasource.async = function() { | ||
return function() { | ||
assert('cloudantNoSQLDB' in datasource.dataServices); | ||
done(); | ||
if (Object.keys(cfConfig).length) { | ||
it('should get service plans', function(done) { | ||
datasource.async = function() { | ||
return function() { | ||
assert('cloudantNoSQLDB' in datasource.dataServices); | ||
done(); | ||
}; | ||
}; | ||
}; | ||
lbBM.ds.getServicePlans(datasource); | ||
}); | ||
lbBM.ds.getServicePlans(datasource); | ||
}); | ||
} | ||
@@ -122,0 +127,0 @@ it('should update datasources-config.json', function(done) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
62982
1549
0