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

144 lines
4.9 KiB
JavaScript
Raw Normal View History

2015-06-13 21:33:42 -07: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
2015-06-16 14:07:31 -07:00
* an update. It then check if the cloudron can be updated to
* the next (unreleased) version.
*/
2015-06-13 21:33:42 -07:00
'use strict';
2015-06-14 21:15:49 -07:00
var AppStore = require('../appstore.js'),
2015-06-13 21:33:42 -07:00
assert = require('assert'),
2015-06-14 21:15:49 -07:00
Cloudron = require('../cloudron.js'),
2015-06-16 19:13:17 -07:00
common = require('../common.js'),
2015-06-16 14:16:37 -07:00
execSync = require('child_process').execSync,
2015-06-13 21:33:42 -07:00
request = require('superagent-sync'),
semver = require('semver'),
2015-06-22 09:14:44 +02:00
sleep = require('sleep').sleep;
2015-06-13 21:33:42 -07:00
require('colors');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
2015-06-15 20:50:39 -07:00
describe('Cloudron update testing', function () {
2015-06-13 21:33:42 -07:00
this.timeout(0);
var appStore = new AppStore('https://api.staging.cloudron.io');
2015-07-23 13:46:47 -07:00
var owner = common.getOwner();
2015-06-16 14:07:31 -07:00
var res, fromVersion, toVersion, cloudron, appId, box, nextVersion;
2015-06-13 21:33:42 -07:00
2015-07-24 15:49:56 -07:00
before('can release a fake version to staging', function () {
execSync(__dirname + '/../../installer/release/release rerelease --env staging', { stdio: [ null, process.stdout, process.stderr ] });
});
after('can revert the fake release from staging', function () {
execSync(__dirname + '/../../installer/release/release revert --env staging', { stdio: [ null, process.stdout, process.stderr ] });
});
2015-06-13 21:33:42 -07:00
it('can query versions', function () {
res = request.get('https://s3.amazonaws.com/staging-cloudron-releases/versions.json').end();
2015-06-19 13:06:00 -07:00
common.verifyResponse(res);
2015-06-13 21:33:42 -07:00
var boxVersions = Object.keys(res.body).sort(semver.rcompare);
2015-07-24 17:34:10 -07:00
fromVersion = boxVersions[2]; // we released a new version in before()
toVersion = boxVersions[1];
2015-06-16 14:07:31 -07:00
nextVersion = semver.inc(toVersion, 'patch');
2015-06-13 21:33:42 -07:00
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-19 13:06:00 -07:00
domain: common.cloudronDomain(__filename),
2015-06-13 21:33:42 -07:00
zoneName: 'smartserver.io',
region: 'sfo1',
size: '512mb',
version: fromVersion
});
2015-06-16 12:00:46 -07:00
appStore.waitForCloudron(box.id);
2015-06-13 21:33:42 -07: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-15 21:49:30 -07:00
var location = 'test' + (Math.random() * 10000).toFixed();
2015-06-13 21:33:42 -07:00
it('can install app', function () {
2015-06-16 19:13:17 -07:00
var manifest = appStore.getManifest(common.TESTAPP_ID, common.TESTAPP_VERSION);
2015-06-13 21:33:42 -07:00
appId = cloudron.installApp(location, manifest);
});
2015-06-15 21:49:30 -07:00
it('can populate the addons', function () {
2015-06-15 22:14:48 -07:00
var res = request.post('https://' + location + '-' + box.domain + '/populate_addons').end();
2015-06-15 21:49:30 -07: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-15 22:06:27 -07:00
var res = request.post('https://' + location + '-' + box.domain + '/check_addons').end();
2015-06-15 21:49:30 -07: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-13 21:33:42 -07:00
});
it('can update the box', function () {
cloudron.update(toVersion);
});
2015-06-15 22:28:48 -07:00
it('runs the app', function () {
cloudron.waitForApp(appId);
});
2015-06-15 21:49:30 -07:00
it('can check the addons', function () {
2015-06-15 22:06:27 -07:00
var res = request.post('https://' + location + '-' + box.domain + '/check_addons').end();
2015-06-15 21:49:30 -07: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-16 14:07:31 -07:00
it('can update to new version', function () {
console.log('Wait for cloudron to get the update');
sleep(60 * 2);
cloudron.update(nextVersion);
});
it('runs the app', function () {
cloudron.waitForApp(appId);
});
it('can check the addons', function () {
var res = request.post('https://' + location + '-' + box.domain + '/check_addons').end();
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-13 21:33:42 -07:00
it('can uninstall app', function () {
cloudron.uninstallApp(appId);
});
it('can delete the cloudron', function () {
appStore.deleteCloudron(box);
});
});