From 92fc9fbd403b00d0278fa1c2732908c36ec32f88 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Sun, 30 Aug 2015 21:48:33 -0700 Subject: [PATCH] Add reboot test --- cloudron.js | 28 +++++++++++++++++++++++++--- test/app-flow-test.js | 13 +++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/cloudron.js b/cloudron.js index f9633a8..4c546fd 100644 --- a/cloudron.js +++ b/cloudron.js @@ -94,10 +94,11 @@ Cloudron.prototype.waitForApp = function (appId) { // wait for app to come up process.stdout.write('Waiting for app to come up.'); + var res; for (var i = 0; i < 60; i++) { sleep(10); process.stdout.write('.'); - var res = request.get(this._origin + '/api/v1/apps/'+ appId).query({ access_token: this._credentials.accessToken }).end(); + res = request.get(this._origin + '/api/v1/apps/'+ appId).query({ access_token: this._credentials.accessToken }).end(); verifyResponse(res, 'Could not query app status'); if (res.body.installationState === 'installed' && res.body.runState === 'running' && res.body.health === 'healthy') { @@ -109,6 +110,21 @@ Cloudron.prototype.waitForApp = function (appId) { assert.strictEqual(res.body.runState, 'running'); }; + +Cloudron.prototype.waitForBox = function () { + process.stdout.write('Waiting for box.'); + var res; + for (var i = 0; i < 40; i++) { + sleep(10); + res = request.get(this._origin + '/api/v1/cloudron/status').end(); + if (res.statusCode === 202) { + console.log(); + break; + } + process.stdout.write('.'); + } +}; + Cloudron.prototype.setCredentials = function (password, accessToken) { this._credentials = { password: password, @@ -166,10 +182,11 @@ Cloudron.prototype.uninstallApp = function (appId) { Cloudron.prototype.update = function (toVersion) { process.stdout.write('Trying to update'); + var res; while (true) { sleep(10); process.stdout.write('.'); - var res = request.post(this._origin + '/api/v1/cloudron/update').query({ access_token: this._credentials.accessToken }).send({ password: this._credentials.password }).end(); + res = request.post(this._origin + '/api/v1/cloudron/update').query({ access_token: this._credentials.accessToken }).send({ password: this._credentials.password }).end(); if (res.statusCode === 422) continue; // box has not seen the update yet verifyResponse(res, 'Could not update'); break; @@ -190,7 +207,7 @@ Cloudron.prototype.update = function (toVersion) { assert.strictEqual(res.body.activated, true); console.log('Updated successfully'.green); -} +}; Cloudron.prototype.addUser = function (username, email) { var res = request.post(this._origin + '/api/v1/users').query({ access_token: this._credentials.accessToken }).send({ username: username, email: email }).end(); @@ -237,3 +254,8 @@ Cloudron.prototype.backup = function () { return latestBackups[0]; // { creationTime, boxVersion, restoreKey, dependsOn } }; +Cloudron.prototype.reboot = function () { + var res = request.post(this._origin + '/api/v1/cloudron/reboot').send({ }).end(); + verifyResponse(res, 'Box could not be rebooted'); + this.waitForBox(); +}; diff --git a/test/app-flow-test.js b/test/app-flow-test.js index 6271718..a8e6c40 100644 --- a/test/app-flow-test.js +++ b/test/app-flow-test.js @@ -97,6 +97,19 @@ describe('Application flow test', function () { assert.strictEqual(res.body.localstorage, 'OK'); }); + it('can reboot the cloudron', function () { + cloudron.reboot(); + }); + + 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'); + assert.strictEqual(res.body.localstorage, 'OK'); + }); + it('can uninstall app', function () { cloudron.uninstallApp(appId); });