From c5602846812b6bdb9ad55711544e112bdd20d93d Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Fri, 15 Apr 2016 19:28:33 -0700 Subject: [PATCH] Add test to update an app --- cloudron.js | 16 +++++++++ parallel_test.sh | 2 +- test/app-update-test.js | 80 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 test/app-update-test.js diff --git a/cloudron.js b/cloudron.js index 64dd8c2..f87da2e 100644 --- a/cloudron.js +++ b/cloudron.js @@ -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; diff --git a/parallel_test.sh b/parallel_test.sh index c659f02..1e3d79f 100755 --- a/parallel_test.sh +++ b/parallel_test.sh @@ -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+=("$!") diff --git a/test/app-update-test.js b/test/app-update-test.js new file mode 100644 index 0000000..1ccd7c0 --- /dev/null +++ b/test/app-update-test.js @@ -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); + }); +}); +