Add reboot test

This commit is contained in:
Girish Ramakrishnan 2015-08-30 21:48:33 -07:00
parent fd22b09e4d
commit 92fc9fbd40
2 changed files with 38 additions and 3 deletions

View File

@ -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();
};

View File

@ -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);
});