cloudron-e2e-test/common.js

71 lines
2.2 KiB
JavaScript
Raw Normal View History

2015-06-17 02:13:17 +00:00
'use strict';
2015-09-29 20:34:43 +00:00
var debug = require('debug')('e2e:common'),
path = require('path'),
2015-09-15 18:55:06 +00:00
safe = require('safetydance'),
util = require('util'),
2015-09-15 18:55:06 +00:00
_ = require('underscore');
2015-06-20 18:49:12 +00:00
2015-06-17 02:13:17 +00:00
exports = module.exports = {
TESTAPP_ID: 'io.cloudron.testapp',
2015-10-23 23:42:02 +00:00
PREV_TESTAPP_VERSION : '9.0.0',
TESTAPP_VERSION : '10.0.0',
2015-06-19 20:06:00 +00:00
cloudronDomain: cloudronDomain,
2015-07-23 20:46:47 +00:00
verifyResponse: verifyResponse,
2015-09-16 19:51:10 +00:00
verifyResponse2: verifyResponse2,
2015-07-23 20:46:47 +00:00
getOwner: getOwner,
2015-09-15 18:55:06 +00:00
stripeSecret: stripeSecret,
stripUnreachable: stripUnreachable
2015-06-17 02:13:17 +00:00
};
2015-07-27 20:31:50 +00:00
var gEcosystem = safe.require(path.join(__dirname, '../keys/ci/ecosystem-prod.json'));
2015-06-19 20:06:00 +00:00
function cloudronDomain(filename) {
2015-11-04 17:52:41 +00:00
return 't' + path.basename(filename.replace(/-/g,''), 'test.js') + '.selfhost.io';
2015-06-19 20:06:00 +00:00
}
2015-09-15 18:55:06 +00:00
function stripUnreachable(releases) {
var reachableVersions = [ ];
var curVersion = '0.0.1';
while (true) {
reachableVersions.push(curVersion);
var nextVersion = releases[curVersion].next;
if (!nextVersion) break;
curVersion = nextVersion;
}
return _.pick(releases, reachableVersions);
}
function verifyResponse2(res, args) {
2015-09-16 19:31:00 +00:00
if (res.statusCode < 200 || res.statusCode > 399) {
debug('Response error statusCode:%s error:%s body:%j', res.statusCode, res.error, res.body);
var errorMessage = util.format.apply(util, Array.prototype.slice.call(arguments, 1));
2015-09-16 19:31:00 +00:00
debug(errorMessage.red);
throw new Error(errorMessage);
}
}
function verifyResponse(res, args) {
2015-06-19 20:06:00 +00:00
if (res.statusCode < 200 || res.statusCode > 299) {
2015-09-16 19:31:28 +00:00
console.log('Response error statusCode:%s error:%s body:%j', res.statusCode, res.error, res.body);
var errorMessage = util.format.apply(util, Array.prototype.slice.call(arguments, 1));
debug(errorMessage.red);
2015-06-19 20:06:00 +00:00
process.exit(1);
}
}
2015-07-23 20:46:47 +00:00
function getOwner() {
return {
2015-07-27 20:31:50 +00:00
username: process.env.APPSTORE_USERNAME || gEcosystem.env.APPSTORE_USERNAME,
password: process.env.APPSTORE_PASSWORD || gEcosystem.env.APPSTORE_PASSWORD,
email: process.env.APPSTORE_EMAIL || gEcosystem.env.APPSTORE_EMAIL
2015-07-23 20:46:47 +00:00
};
}
2015-06-19 20:06:00 +00:00
2015-07-27 20:21:38 +00:00
function stripeSecret() {
2015-07-27 20:31:50 +00:00
return process.env.STRIPE_SECRET || gEcosystem.env.STRIPE_SECRET;
2015-07-27 20:21:38 +00:00
}