mirror of
https://git.cloudron.io/cloudron/prometheus-server-app.git
synced 2024-11-22 08:21:02 +00:00
130 lines
4.8 KiB
JavaScript
130 lines
4.8 KiB
JavaScript
|
#!/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');
|
||
|
|
||
|
const execSync = require('child_process').execSync,
|
||
|
expect = require('expect.js'),
|
||
|
path = require('path');
|
||
|
|
||
|
var By = require('selenium-webdriver').By,
|
||
|
until = require('selenium-webdriver').until,
|
||
|
Key = require('selenium-webdriver').Key,
|
||
|
Builder = require('selenium-webdriver').Builder;
|
||
|
|
||
|
if (!process.env.USERNAME || !process.env.PASSWORD) {
|
||
|
console.log('USERNAME 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 = process.env.USERNAME;
|
||
|
var password = process.env.PASSWORD;
|
||
|
|
||
|
var LOCATION = 'test';
|
||
|
var EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
|
||
|
var TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 50000;
|
||
|
|
||
|
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.xpath('//input[@name="username"]')), TIMEOUT);
|
||
|
}).then(function () {
|
||
|
return browser.findElement(By.xpath('//input[@name="username"]')).sendKeys(username);
|
||
|
}).then(function () {
|
||
|
return browser.findElement(By.xpath('//input[@name="password"]')).sendKeys(password);
|
||
|
}).then(function () {
|
||
|
return browser.findElement(By.tagName('form')).submit();
|
||
|
}).then(function () {
|
||
|
return browser.wait(until.elementLocated(By.xpath('//a[text()="Alerts"]')), TIMEOUT);
|
||
|
}).then(function () {
|
||
|
done();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function logout(done) {
|
||
|
browser.get(`https://${app.fqdn}/logout`).then(function () {
|
||
|
return browser.wait(until.elementLocated(By.xpath('//input[@name="username"]')), TIMEOUT);
|
||
|
}).then(function () {
|
||
|
done();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
before(function (done) {
|
||
|
if (!process.env.PASSWORD) return done(new Error('PASSWORD env var not set'));
|
||
|
|
||
|
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();
|
||
|
});
|
||
|
|
||
|
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
|
||
|
|
||
|
it('install app', function () { execSync(`cloudron install --location ${LOCATION}`, EXEC_ARGS); });
|
||
|
|
||
|
it('can get app information', getAppInfo);
|
||
|
|
||
|
it('can login', login);
|
||
|
it('can logout', logout);
|
||
|
|
||
|
it('can restart app', function () { execSync(`cloudron restart --app ${app.id}`, EXEC_ARGS); });
|
||
|
it('can login', login);
|
||
|
it('can logout', logout);
|
||
|
|
||
|
it('backup app', function () { execSync(`cloudron backup create --app ${app.id}`, EXEC_ARGS); });
|
||
|
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' });
|
||
|
var inspect = JSON.parse(execSync('cloudron inspect'));
|
||
|
app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
|
||
|
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
||
|
});
|
||
|
|
||
|
it('can login', login);
|
||
|
it('can logout', logout);
|
||
|
|
||
|
it('move to different location', function () { execSync(`cloudron configure --location ${LOCATION}2 --app ${app.id}`, EXEC_ARGS); });
|
||
|
it('can get app information', getAppInfo);
|
||
|
it('can login', login);
|
||
|
it('can logout', logout);
|
||
|
|
||
|
it('uninstall app', function () { execSync(`cloudron uninstall --app ${app.id}`, EXEC_ARGS); });
|
||
|
|
||
|
// test update
|
||
|
it('can install app', function () { execSync(`cloudron install --appstore-id io.prometheus.cloudronapp --location ${LOCATION}`, EXEC_ARGS); });
|
||
|
it('can get app information', getAppInfo);
|
||
|
it('can update', function () { execSync(`cloudron update --app ${app.id}`, EXEC_ARGS); });
|
||
|
it('can login', login);
|
||
|
it('can logout', logout);
|
||
|
it('uninstall app', function () { execSync(`cloudron uninstall --app ${app.id}`, EXEC_ARGS); });
|
||
|
});
|
||
|
|