initial tests

This commit is contained in:
Girish Ramakrishnan 2020-07-21 13:46:54 -07:00
parent a0d74d4bca
commit 2effab3922
3 changed files with 1281 additions and 0 deletions

1116
test/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

25
test/package.json Normal file
View file

@ -0,0 +1,25 @@
{
"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"
},
"dependencies": {
"chromedriver": "^2.38.3",
"selenium-server-standalone-jar": "^3.3.1",
"selenium-webdriver": "^3.3.0",
"superagent": "^1.8.5"
}
}

140
test/test.js Normal file
View file

@ -0,0 +1,140 @@
#!/usr/bin/env node
/* jslint node:true */
/* global it:false */
/* global xit:false */
/* global describe:false */
/* global before:false */
/* global after:false */
'use strict';
require('chromedriver');
var execSync = require('child_process').execSync,
expect = require('expect.js'),
path = require('path'),
superagent = require('superagent'),
webdriver = require('selenium-webdriver'),
util = require('util');
var by = webdriver.By,
Keys = webdriver.Key,
until = webdriver.until,
Builder = require('selenium-webdriver').Builder;
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
if (!process.env.USERNAME || !process.env.PASSWORD || !process.env.EMAIL) {
console.log('USERNAME, EMAIL and PASSWORD env vars need to be set');
process.exit(1);
}
describe('Application life cycle test', function () {
this.timeout(0);
var server, browser = new Builder().forBrowser('chrome').build();
var username = 'root';
var password = 'changeme';
var email = process.env.EMAIL;
before(function (done) {
var seleniumJar= require('selenium-server-standalone-jar');
var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
server = new SeleniumServer(seleniumJar.path, { port: 4444 });
server.start();
done();
});
after(function (done) {
browser.quit();
server.stop();
done();
});
var LOCATION = 'test';
var TEST_TIMEOUT = parseInt(process.env.TEST_TIMEOUT, 10) || 30000;
var app;
function getAppInfo() {
var inspect = JSON.parse(execSync('cloudron inspect'));
app = inspect.apps.filter(function (a) { return a.location === LOCATION || a.location === LOCATION + '2'; })[0];
expect(app).to.be.an('object');
}
function login(done) {
browser.get('https://' + app.fqdn + '/login').then(function () {
return browser.wait(until.elementLocated(by.id('username')), TEST_TIMEOUT);
}).then(function () {
return browser.findElement(by.name('username')).sendKeys(username);
}).then(function () {
return browser.findElement(by.name('password')).sendKeys(password);
}).then(function () {
return browser.findElement(by.xpath('//input[@value="Login"]')).click();
}).then(function () {
return browser.wait(until.elementLocated(by.xpath('//h2[contains(text(), "Welcome to PeerTube")]')), TEST_TIMEOUT);
}).then(function () {
done();
});
}
xit('build app', function () {
execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('install app', function () {
execSync('cloudron install --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('can get app information', getAppInfo);
it('can login', login);
it('backup app', function () {
execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('restore app', function () {
const backups = JSON.parse(execSync('cloudron backup list --raw'));
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
execSync('cloudron install --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
getAppInfo();
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('can login', login);
it('can restart app', function () {
execSync('cloudron restart --app ' + app.id);
});
it('can login', login);
it('move to different location', function (done) {
execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
done();
});
it('can get app information', getAppInfo);
it('can login', login);
it('uninstall app', function () {
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
// test update
it('can install app', function () {
execSync('cloudron install --appstore-id ' + app.manifest.id + ' --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('can get app information', getAppInfo);
it('can login', login);
it('can update', function () {
execSync('cloudron update --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' });
});
});