Commit 30083ee1 authored by Johannes Zellner's avatar Johannes Zellner

Update app tests

request module is deprecated, add backup/restore tests to test storage
backends, since the app has special filenames and all
parent 2ff235df
This diff is collapsed.
......@@ -10,7 +10,7 @@
"license": "ISC",
"dependencies": {
"expect.js": "^0.3.1",
"mocha": "^7.1.2",
"request": "^2.88.2"
"mocha": "^8.0.1",
"superagent": "^5.2.2"
}
}
......@@ -9,10 +9,14 @@
var execSync = require('child_process').execSync,
expect = require('expect.js'),
path = require('path'),
request = require('request');
superagent = require('superagent');
const LOCATION = 'test';
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
var app;
var apiOrigin;
var accessToken;
const USERNAME = process.env.USERNAME;
const PASSWORD = process.env.PASSWORD;
......@@ -22,6 +26,60 @@ if (!USERNAME || !PASSWORD) {
process.exit(1);
}
function getAppInfo(done) {
var inspect = JSON.parse(execSync('cloudron inspect'));
app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
expect(app).to.be.an('object');
// TODO this is not always correct
apiOrigin = 'https://my.' + app.domain;
superagent.post(`${apiOrigin}/api/v1/cloudron/login`).send({ username: USERNAME, password: PASSWORD }).end(function (error, result) {
expect(error).to.eql(null);
expect(result.statusCode).to.eql(200);
accessToken = result.body.accessToken;
done();
});
}
function canReachApp(done) {
superagent.get(`https://${app.fqdn}/`).end(function (error, result) {
expect(error).to.eql(null);
expect(result.statusCode).to.eql(200);
done();
});
}
function checkAddons(done) {
superagent.get(`https://${app.fqdn}/check_addons?username=${USERNAME}&password=${encodeURIComponent(PASSWORD)}`).end(function (error, result) {
expect(error).to.eql(null);
expect(result.statusCode).to.eql(200);
console.dir(result.body);
expect(result.body.mysql).to.eql('OK');
expect(result.body.postgresql).to.eql('OK');
expect(result.body.redis).to.eql('OK');
expect(result.body.mongodb).to.eql('OK');
expect(result.body.localstorage).to.eql('OK');
expect(result.body.stdenv).to.eql('OK');
expect(result.body.docker).to.eql('OK');
expect(result.body.net_admin).to.eql('OK');
expect(result.body.scheduler).to.eql('OK');
expect(result.body.email).to.eql('OK');
expect(result.body.ldap).to.eql('OK');
done();
});
}
function waitForScheduler(done) {
console.log('Waiting for 2mins for scheduler to be run');
setTimeout(done, 2 * 60 * 1000);
}
describe('Test app', function () {
this.timeout(0);
......@@ -31,75 +89,62 @@ describe('Test app', function () {
console.log();
console.log();
it('can install app', function () {
execSync(`cloudron install --location ${LOCATION}`, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
var inspect = JSON.parse(execSync('cloudron inspect'));
it('can install app', function () { execSync(`cloudron install --location ${LOCATION}`, EXEC_ARGS); });
it('can get app information', getAppInfo);
app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
it('can reach app', canReachApp);
expect(app).to.be.an('object');
});
it('can set app mailbox', function (done) {
let data = {
mailboxName: USERNAME,
mailboxDomain: app.domain
};
it('can reach app', function (done) {
request.get(`https://${app.fqdn}/`, function (error, response, body) {
superagent.post(`${apiOrigin}/api/v1/apps/${app.id}/configure/mailbox`).query({ access_token: accessToken }).send(data).end(function (error, result) {
expect(error).to.eql(null);
expect(response.statusCode).to.eql(200);
done();
});
});
expect(result.statusCode).to.eql(202);
it('can populate addons', function (done) {
request.get(`https://${app.fqdn}/populate_addons`, function (error, response, body) {
expect(error).to.eql(null);
expect(response.statusCode).to.eql(200);
function waitForApp(callback) {
superagent.get(`${apiOrigin}/api/v1/apps/${app.id}`).query({ access_token: accessToken }).end(function (error, result) {
if (error && !error.response) return callback(new Error('network error:' + error));
if (result.statusCode !== 200) return waitForApp(callback);
body = JSON.parse(body);
if (result.body.installationState === 'installed' && result.body.runState === 'running' && result.body.health === 'healthy') {
return callback(null);
}
expect(body.mysql).to.eql('OK');
expect(body.postgresql).to.eql('OK');
expect(body.redis).to.eql('OK');
expect(body.mongodb).to.eql('OK');
expect(body.localstorage).to.eql('OK');
setTimeout(waitForApp.bind(null, callback), 2000);
});
}
done();
waitForApp(done);
});
});
it('wait for 2 minutes for scheduler', function (done) {
console.log('Waiting for 2mins for scheduler to be run');
setTimeout(done, 2 * 60 * 1000);
});
it('can check addons', function (done) {
const url = `https://${app.fqdn}/check_addons?username=${USERNAME}&password=${encodeURIComponent(PASSWORD)}`;
console.log('checking addons', url);
request.get(url, function (error, response, body) {
it('can populate addons', function (done) {
superagent.get(`https://${app.fqdn}/populate_addons`).end(function (error, result) {
expect(error).to.eql(null);
expect(response.statusCode).to.eql(200);
console.dir(body);
body = JSON.parse(body);
expect(body.mysql).to.eql('OK');
expect(body.postgresql).to.eql('OK');
expect(body.redis).to.eql('OK');
expect(body.mongodb).to.eql('OK');
expect(body.localstorage).to.eql('OK');
expect(body.stdenv).to.eql('OK');
expect(body.docker).to.eql('OK');
expect(body.net_admin).to.eql('OK');
expect(body.scheduler).to.eql('OK');
expect(body.email).to.eql('OK');
expect(body.ldap).to.eql('OK');
expect(result.statusCode).to.eql(200);
expect(result.body.mysql).to.eql('OK');
expect(result.body.postgresql).to.eql('OK');
expect(result.body.redis).to.eql('OK');
expect(result.body.mongodb).to.eql('OK');
expect(result.body.localstorage).to.eql('OK');
done();
});
});
it('can uninstall app', function () {
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('wait for 2 minutes for scheduler', waitForScheduler);
it('can check addons', checkAddons);
it('backup app', function () { execSync(`cloudron backup create --app ${app.id}`, EXEC_ARGS); });
it('restore app', function () { execSync(`cloudron restore --app ${app.id}`, EXEC_ARGS); });
it('can reach app', canReachApp);
it('wait for 2 minutes for scheduler', waitForScheduler);
it('can check addons', checkAddons);
it('can uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment