]> git.immae.eu Git - perso/Immae/Projets/Nodejs/Surfer.git/blame - test/test.js
Enable build test
[perso/Immae/Projets/Nodejs/Surfer.git] / test / test.js
CommitLineData
ebd7ed7a
GR
1#!/usr/bin/env node
2
3'use strict';
4
5var execSync = require('child_process').execSync,
6 expect = require('expect.js'),
755569a3
GR
7 fs = require('fs'),
8 os = require('os'),
ebd7ed7a
GR
9 path = require('path'),
10 superagent = require('superagent');
11
12process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
13
14describe('Application life cycle test', function () {
15 this.timeout(0);
16 var LOCATION = 'surfertest';
755569a3 17 var app, testFile = os.tmpdir() + '/surfer-test.txt';
ebd7ed7a
GR
18 var username = process.env.USERNAME;
19 var password = process.env.PASSWORD;
20
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'));
24
25 done();
26 });
27
28 after(function (done) {
29 done();
30 });
31
de9b8cee 32 it('build app', function () {
ebd7ed7a
GR
33 execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
34 });
35
052333b5 36 it('install app', function () {
ebd7ed7a
GR
37 execSync('cloudron install --new --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
38 });
39
40 it('can get app information', function () {
41 var inspect = JSON.parse(execSync('cloudron inspect'));
42
43 app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
44
45 expect(app).to.be.an('object');
46 });
47
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);
52
53 done();
54 });
55 });
56
755569a3
GR
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 }));
ebd7ed7a
GR
60 });
61
62 it('can upload file', function (done) {
755569a3
GR
63 fs.writeFileSync(testFile, 'surfer');
64 execSync(__dirname + '/../cli/surfer.js put ' + testFile, { stdio: 'inherit' } );
ebd7ed7a
GR
65 done();
66 });
67
68 it('backup app', function () {
69 execSync('cloudron backup --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
70 });
71
72 it('restore app', function () {
73 execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
74 });
75
76 it('can get the uploaded file', function (done) {
052333b5 77 var contents = execSync(__dirname + '/../cli/surfer.js get surfer-test.txt').toString('utf8');
755569a3 78 expect(contents).to.be('surfer');
ebd7ed7a
GR
79 done();
80 });
81
052333b5 82 it('uninstall app', function () {
ebd7ed7a 83 execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
755569a3
GR
84 fs.unlinkSync(process.env.HOME + '/.surfer.json');
85 fs.unlinkSync(testFile);
ebd7ed7a
GR
86 });
87});