5 var execSync
= require('child_process').execSync
,
6 expect
= require('expect.js'),
9 path
= require('path'),
10 superagent
= require('superagent');
12 process
.env
.NODE_TLS_REJECT_UNAUTHORIZED
= '0';
14 describe('Application life cycle test', function () {
16 var LOCATION
= 'surfertest';
17 var app
, testFile
= os
.tmpdir() + '/surfer-test.txt';
18 var username
= process
.env
.USERNAME
;
19 var password
= process
.env
.PASSWORD
;
21 before(function (done
) {
22 if (!process
.env
.USERNAME
) return done(new Error('USERNAME env var not set'));
23 if (!process
.env
.PASSWORD
) return done(new Error('PASSWORD env var not set'));
28 after(function (done
) {
32 xit('build app', function () {
33 execSync('cloudron build', { cwd: path
.resolve(__dirname
, '..'), stdio: 'inherit' });
36 it('install app', function () {
37 execSync('cloudron install --new --location ' + LOCATION
, { cwd: path
.resolve(__dirname
, '..'), stdio: 'inherit' });
40 it('can get app information', function () {
41 var inspect
= JSON
.parse(execSync('cloudron inspect'));
43 app
= inspect
.apps
.filter(function (a
) { return a
.location
=== LOCATION
; })[0];
45 expect(app
).to
.be
.an('object');
48 it('can get the main page', function (done
) {
49 superagent
.get('https://' + app
.fqdn
).end(function (error
, result
) {
50 expect(error
).to
.be(null);
51 expect(result
.status
).to
.eql(200);
57 it('can login using cli', function () {
58 // execSync(__dirname + '/../cli/surfer.js login https://' + app.fqdn, { input: username + '\n' + password + '\n' });
59 fs
.writeFileSync(process
.env
.HOME
+ '/.surfer.json', JSON
.stringify({ server: 'https://' + app
.fqdn
, username: username
, password: password
}));
62 it('can upload file', function (done
) {
63 fs
.writeFileSync(testFile
, 'surfer');
64 execSync(__dirname
+ '/../cli/surfer.js put ' + testFile
, { stdio: 'inherit' } );
68 it('backup app', function () {
69 execSync('cloudron backup --app ' + app
.id
, { cwd: path
.resolve(__dirname
, '..'), stdio: 'inherit' });
72 it('restore app', function () {
73 execSync('cloudron restore --app ' + app
.id
, { cwd: path
.resolve(__dirname
, '..'), stdio: 'inherit' });
76 it('can get the uploaded file', function (done
) {
77 var contents
= execSync(__dirname
+ '/../cli/surfer.js get surfer-test.txt').toString('utf8');
78 expect(contents
).to
.be('surfer');
82 it('uninstall app', function () {
83 execSync('cloudron uninstall --app ' + app
.id
, { cwd: path
.resolve(__dirname
, '..'), stdio: 'inherit' });
84 fs
.unlinkSync(process
.env
.HOME
+ '/.surfer.json');
85 fs
.unlinkSync(testFile
);