cloudron-e2e-test/test/update-test.js

134 lines
4.1 KiB
JavaScript
Raw Normal View History

2015-06-14 04:33:42 +00:00
#!/usr/bin/env node
/*
* This tests a flow for the cloudron owner updating a cloudron.
* It checks if an existing installed app retains it's data after
* an update.
*/
2015-06-14 04:33:42 +00:00
'use strict';
2015-06-15 04:15:49 +00:00
var AppStore = require('../appstore.js'),
2015-06-14 04:33:42 +00:00
assert = require('assert'),
2015-06-15 04:15:49 +00:00
Cloudron = require('../cloudron.js'),
2015-06-15 04:29:02 +00:00
path = require('path'),
2015-06-14 04:33:42 +00:00
readlineSync = require('readline-sync'),
request = require('superagent-sync'),
semver = require('semver'),
util = require('util');
require('colors');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
2015-06-16 16:59:22 +00:00
function cloudronName() {
var r = (Math.random() * 1000).toFixed();
return 't-' + path.basename(__filename, '-test.js') + '-' + r + '.smartserver.io';
}
2015-06-14 04:33:42 +00:00
function verifyResponse(res, errorMessage) {
if (res.statusCode < 200 || res.statusCode > 299) {
console.log('Response error statusCode:%s error:%s body:%s', res.statusCode, res.error, res.body);
console.log(errorMessage.red);
process.exit(1);
}
}
2015-06-16 03:50:39 +00:00
describe('Cloudron update testing', function () {
2015-06-14 04:33:42 +00:00
this.timeout(0);
var appStore = new AppStore('https://api.staging.cloudron.io');
var owner = {
username: 'test',
password: 'test1234',
email: 'test@cloudron.io'
};
var res, fromVersion, toVersion, cloudron, appId, box;
it('can query versions', function () {
res = request.get('https://s3.amazonaws.com/staging-cloudron-releases/versions.json').end();
verifyResponse(res);
var boxVersions = Object.keys(res.body).sort(semver.rcompare);
fromVersion = boxVersions[1];
toVersion = boxVersions[0];
console.log('Will test update from %s to %s', fromVersion.yellow, toVersion.yellow);
});
it('can login to the store', function () {
var accessToken = appStore.getAccessToken(owner);
appStore.setCredentials(owner.password, accessToken);
});
it('can create a cloudron', function () {
box = appStore.createCloudron({
2015-06-16 16:59:22 +00:00
name: cloudronName(),
2015-06-14 04:33:42 +00:00
zoneName: 'smartserver.io',
region: 'sfo1',
size: '512mb',
version: fromVersion
});
2015-06-16 19:00:46 +00:00
appStore.waitForCloudron(box.id);
2015-06-14 04:33:42 +00:00
cloudron = new Cloudron(box);
});
it('can activate the box', function () {
cloudron.activate(owner);
});
it('can login to the box', function () {
var token = cloudron.getOauthToken(owner);
cloudron.setCredentials(owner.password, token);
});
2015-06-16 04:49:30 +00:00
var location = 'test' + (Math.random() * 10000).toFixed();
2015-06-14 04:33:42 +00:00
it('can install app', function () {
2015-06-16 04:49:30 +00:00
var manifest = appStore.getManifest('io.cloudron.testapp', '1.0.0');
2015-06-14 04:33:42 +00:00
appId = cloudron.installApp(location, manifest);
});
2015-06-16 04:49:30 +00:00
it('can populate the addons', function () {
2015-06-16 05:14:48 +00:00
var res = request.post('https://' + location + '-' + box.domain + '/populate_addons').end();
2015-06-16 04:49:30 +00:00
assert.strictEqual(res.statusCode, 200);
assert.strictEqual(res.body.mysql, 'OK');
assert.strictEqual(res.body.postgresql, 'OK');
assert.strictEqual(res.body.mongodb, 'OK');
});
it('can check the addons', function () {
2015-06-16 05:06:27 +00:00
var res = request.post('https://' + location + '-' + box.domain + '/check_addons').end();
2015-06-16 04:49:30 +00:00
assert.strictEqual(res.statusCode, 200);
assert.strictEqual(res.body.mysql, 'OK');
assert.strictEqual(res.body.postgresql, 'OK');
assert.strictEqual(res.body.mongodb, 'OK');
2015-06-14 04:33:42 +00:00
});
it('can update the box', function () {
cloudron.update(toVersion);
});
2015-06-16 05:28:48 +00:00
it('runs the app', function () {
cloudron.waitForApp(appId);
});
2015-06-16 04:49:30 +00:00
it('can check the addons', function () {
2015-06-16 05:06:27 +00:00
var res = request.post('https://' + location + '-' + box.domain + '/check_addons').end();
2015-06-16 04:49:30 +00:00
assert.strictEqual(res.statusCode, 200);
assert.strictEqual(res.body.mysql, 'OK');
assert.strictEqual(res.body.postgresql, 'OK');
assert.strictEqual(res.body.mongodb, 'OK');
});
2015-06-14 04:33:42 +00:00
it('can uninstall app', function () {
cloudron.uninstallApp(appId);
});
it('can delete the cloudron', function () {
appStore.deleteCloudron(box);
});
});