Add test to update an app

This commit is contained in:
Girish Ramakrishnan 2016-04-15 19:28:33 -07:00
parent 313c0573e3
commit c560284681
3 changed files with 97 additions and 1 deletions

View File

@ -213,6 +213,22 @@ Cloudron.prototype.uninstallApp = function (appId) {
assert(false, 'uninstallApp failed');
};
Cloudron.prototype.updateApp = function (appId, newManifest) {
process.stdout.write('Trying to update');
var res;
var res = request.post(this._origin + '/api/v1/apps/' + appId + '/update').query({ access_token: this._credentials.accessToken }).send({ password: this._credentials.password, manifest: newManifest }).end();
common.verifyResponse2xx(res, 'Could not update');
console.log('Update started'.green);
var app = this.waitForApp(appId);
debug('App is running'.green);
res = request.get('https://' + app.fqdn).end();
common.verifyResponse2xx(res, 'App is unreachable');
console.log('App updated'.green);
};
Cloudron.prototype.update = function (toVersion) {
process.stdout.write('Trying to update');
var res;

View File

@ -18,7 +18,7 @@ if ! ./node_modules/.bin/mocha --bail test/before.js > "logs/before.log" 2>&1; t
fi
# run tests
readonly tests=(app-flow-test cloudron-user-test new-user-test cloudron-backup-test custom-domain-test cloudron-update-sfo1-test cloudron-update-ams3-test)
readonly tests=(app-flow-test app-update-test cloudron-user-test new-user-test cloudron-backup-test custom-domain-test cloudron-update-sfo1-test cloudron-update-ams3-test)
for t in "${tests[@]}"; do
./node_modules/.bin/mocha --bail "test/${t}.js" > "logs/${t}.log" 2>&1 &
test_pids+=("$!")

80
test/app-update-test.js Normal file
View File

@ -0,0 +1,80 @@
#!/usr/bin/env node
/*
* This tests an app update on the cloudron. There are
* two versions of haste in the staging appstore
* com.hastebin.cloudronapp@0.1.1 and com.hastebin.cloudronapp@0.3.0
*/
'use strict';
var AppStore = require('../appstore.js'),
assert = require('assert'),
Cloudron = require('../cloudron.js'),
common = require('../common.js'),
request = require('superagent-sync');
require('colors');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
var BOX_VERSION = process.env.BOX_VERSION;
var APP_ID = 'com.hastebin.cloudronapp', APP_OLD_VERSION = '0.1.1', APP_NEW_VERSION = '0.3.0';
describe('Application update test', function () {
this.timeout(0);
var appStore = new AppStore('https://api.staging.cloudron.io');
var owner = common.getOwner();
var admin = common.getAdmin();
var cloudron, appId, box;
it('can login to the store', function () {
var accessToken = appStore.getAccessToken(owner);
appStore.setCredentials(owner.password, accessToken);
var adminAccessToken = appStore.getAccessToken(admin);
appStore.setAdminCredentials(admin.password, adminAccessToken);
});
it('can create a cloudron', function () {
box = appStore.createCloudron({
domain: common.cloudronDomain(__filename),
region: 'sfo1',
size: '1gb',
version: BOX_VERSION
});
box = appStore.waitForCloudron(box.id);
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);
});
var location = 'test' + (Math.random() * 10000).toFixed();
it('can install app', function () {
var manifest = appStore.getManifest(common.APP_ID, common.APP_OLD_VERSION);
appId = cloudron.installApp(location, manifest);
});
it('update the app', function () {
var manifest = appStore.getManifest(common.APP_ID, common.APP_NEW_VERSION);
cloudron.updateApp(appId, manifest);
});
it('can uninstall app', function () {
cloudron.uninstallApp(appId);
});
it('can delete the cloudron', function () {
appStore.deleteCloudron(box);
});
});