From 4084f590f9a4936658c12d8e1e92bd8e377028a5 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Tue, 24 Nov 2015 13:59:52 -0800 Subject: [PATCH] Add tests --- README.md | 2 +- test/package.json | 19 +++++++++++++++ test/test.js | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 test/package.json create mode 100755 test/test.js diff --git a/README.md b/README.md index 216e4b6..3f65cc5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/test/package.json b/test/package.json new file mode 100644 index 0000000..44220b0 --- /dev/null +++ b/test/package.json @@ -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" + } +} diff --git a/test/test.js b/test/test.js new file mode 100755 index 0000000..2432952 --- /dev/null +++ b/test/test.js @@ -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' }); + }); +}); +