Add tests

This commit is contained in:
Girish Ramakrishnan 2015-11-24 13:59:52 -08:00
parent 1e8da01418
commit 4084f590f9
3 changed files with 81 additions and 1 deletions

View File

@ -25,7 +25,7 @@ cloudron install
## Testing
The e2e tests are located in the `test/` folder and require [nodejs](http://nodejs.org/). They are creating a fresh build, install the app on your Cloudron, perform tests, backup, restore and test if the repos are still ok.
The e2e tests are located in the `test/` folder and require [nodejs](http://nodejs.org/). They are creating a fresh build, install the app on your Cloudron, perform tests, backup, restore and test if the repos are still ok. The tests expect port 29418 to be available.
```
cd gogs-app/test

19
test/package.json Normal file
View File

@ -0,0 +1,19 @@
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "test.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"ejs": "^2.3.4",
"expect.js": "^0.3.1",
"mkdirp": "^0.5.1",
"mocha": "^2.3.4",
"rimraf": "^2.4.4",
"superagent": "^1.4.0"
}
}

61
test/test.js Executable file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env node
'use strict';
var execSync = require('child_process').execSync,
ejs = require('ejs'),
expect = require('expect.js'),
fs = require('fs'),
mkdirp = require('mkdirp'),
path = require('path'),
rimraf = require('rimraf'),
superagent = require('superagent');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
describe('Application life cycle test', function () {
this.timeout(0);
var LOCATION = 'test' + Date.now();
var app;
var username = process.env.USERNAME;
var password = process.env.PASSWORD;
it('build app', function () {
execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('install app', function () {
execSync('cloudron install --new --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('can get app information', function () {
var inspect = JSON.parse(execSync('cloudron inspect'));
app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
expect(app).to.be.an('object');
});
it('can get the main page', function (done) {
superagent.get('https://' + app.fqdn).end(function (error, result) {
expect(error).to.be(null);
expect(result.status).to.eql(200);
done();
});
});
it('backup app', function () {
execSync('cloudron backup --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('restore app', function () {
execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('uninstall app', function () {
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
});