mirror of
https://git.cloudron.io/cloudron/prometheus-server-app.git
synced 2024-11-21 16:01:03 +00:00
Fixup tests
This commit is contained in:
parent
b7240f4b23
commit
523fb48df3
1 changed files with 47 additions and 63 deletions
110
test/test.js
110
test/test.js
|
@ -1,24 +1,20 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
/* jslint node:true */
|
/* jshint esversion: 8 */
|
||||||
/* global it:false */
|
/* global describe */
|
||||||
/* global xit:false */
|
/* global before */
|
||||||
/* global describe:false */
|
/* global after */
|
||||||
/* global before:false */
|
/* global it */
|
||||||
/* global after:false */
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
require('chromedriver');
|
require('chromedriver');
|
||||||
|
|
||||||
const execSync = require('child_process').execSync,
|
var execSync = require('child_process').execSync,
|
||||||
expect = require('expect.js'),
|
expect = require('expect.js'),
|
||||||
path = require('path');
|
path = require('path'),
|
||||||
|
{ Builder, By, Key, until } = require('selenium-webdriver'),
|
||||||
var By = require('selenium-webdriver').By,
|
{ Options } = require('selenium-webdriver/chrome');
|
||||||
until = require('selenium-webdriver').until,
|
|
||||||
Key = require('selenium-webdriver').Key,
|
|
||||||
Builder = require('selenium-webdriver').Builder;
|
|
||||||
|
|
||||||
if (!process.env.USERNAME || !process.env.PASSWORD) {
|
if (!process.env.USERNAME || !process.env.PASSWORD) {
|
||||||
console.log('USERNAME and PASSWORD env vars need to be set');
|
console.log('USERNAME and PASSWORD env vars need to be set');
|
||||||
|
@ -28,65 +24,53 @@ if (!process.env.USERNAME || !process.env.PASSWORD) {
|
||||||
describe('Application life cycle test', function () {
|
describe('Application life cycle test', function () {
|
||||||
this.timeout(0);
|
this.timeout(0);
|
||||||
|
|
||||||
var server, browser = new Builder().forBrowser('chrome').build();
|
const LOCATION = 'test';
|
||||||
|
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
|
||||||
|
const TEST_TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 50000;
|
||||||
|
|
||||||
|
var browser;
|
||||||
var username = process.env.USERNAME;
|
var username = process.env.USERNAME;
|
||||||
var password = process.env.PASSWORD;
|
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;
|
var app;
|
||||||
|
|
||||||
|
before(function () {
|
||||||
|
const options = new Options().windowSize({ width: 1280, height: 1024 });
|
||||||
|
if (process.env.HEADLESS) options.addArguments('headless');
|
||||||
|
|
||||||
|
browser = new Builder().forBrowser('chrome').setChromeOptions(options).build();
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function () {
|
||||||
|
browser.quit();
|
||||||
|
});
|
||||||
|
|
||||||
|
async function waitForElement(elem) {
|
||||||
|
await browser.wait(until.elementLocated(elem), TEST_TIMEOUT);
|
||||||
|
await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
function getAppInfo() {
|
function getAppInfo() {
|
||||||
var inspect = JSON.parse(execSync('cloudron inspect'));
|
var inspect = JSON.parse(execSync('cloudron inspect'));
|
||||||
app = inspect.apps.filter(function (a) { return a.location === LOCATION || a.location === LOCATION + '2'; })[0];
|
app = inspect.apps.filter(function (a) { return a.location.indexOf(LOCATION) === 0; })[0];
|
||||||
expect(app).to.be.an('object');
|
expect(app).to.be.an('object');
|
||||||
}
|
}
|
||||||
|
|
||||||
function login(done) {
|
async function login() {
|
||||||
browser.get(`https://${app.fqdn}/login`).then(function () {
|
await browser.get(`https://${app.fqdn}/login`);
|
||||||
return browser.wait(until.elementLocated(By.xpath('//input[@name="username"]')), TIMEOUT);
|
await waitForElement(By.xpath('//input[@name="username"]'));
|
||||||
}).then(function () {
|
await browser.findElement(By.xpath('//input[@name="username"]')).sendKeys(username);
|
||||||
return browser.findElement(By.xpath('//input[@name="username"]')).sendKeys(username);
|
await browser.findElement(By.xpath('//input[@name="password"]')).sendKeys(password);
|
||||||
}).then(function () {
|
await browser.findElement(By.id('login')).click();
|
||||||
return browser.findElement(By.xpath('//input[@name="password"]')).sendKeys(password);
|
await waitForElement(By.xpath('//a[text()="Alerts"]'));
|
||||||
}).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) {
|
async function logout() {
|
||||||
browser.get(`https://${app.fqdn}/logout`).then(function () {
|
await browser.get(`https://${app.fqdn}/logout`);
|
||||||
return browser.wait(until.elementLocated(By.xpath('//input[@name="username"]')), TIMEOUT);
|
await waitForElement(By.xpath('//input[@name="username"]'));
|
||||||
}).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); });
|
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
|
||||||
|
|
||||||
it('install app', function () { execSync(`cloudron install --location ${LOCATION}`, EXEC_ARGS); });
|
it('install app', function () { execSync(`cloudron install --location ${LOCATION}`, EXEC_ARGS); });
|
||||||
|
|
||||||
it('can get app information', getAppInfo);
|
it('can get app information', getAppInfo);
|
||||||
|
@ -100,12 +84,11 @@ describe('Application life cycle test', function () {
|
||||||
|
|
||||||
it('backup app', function () { execSync(`cloudron backup create --app ${app.id}`, EXEC_ARGS); });
|
it('backup app', function () { execSync(`cloudron backup create --app ${app.id}`, EXEC_ARGS); });
|
||||||
it('restore app', function () {
|
it('restore app', function () {
|
||||||
const backups = JSON.parse(execSync('cloudron backup list --raw'));
|
const backups = JSON.parse(execSync(`cloudron backup list --raw --app ${app.id}`));
|
||||||
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
|
||||||
execSync('cloudron install --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
execSync('cloudron install --location ' + LOCATION, EXEC_ARGS);
|
||||||
var inspect = JSON.parse(execSync('cloudron inspect'));
|
getAppInfo();
|
||||||
app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
|
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, EXEC_ARGS);
|
||||||
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can login', login);
|
it('can login', login);
|
||||||
|
@ -113,6 +96,7 @@ describe('Application life cycle test', function () {
|
||||||
|
|
||||||
it('move to different location', function () { execSync(`cloudron configure --location ${LOCATION}2 --app ${app.id}`, EXEC_ARGS); });
|
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 get app information', getAppInfo);
|
||||||
|
|
||||||
it('can login', login);
|
it('can login', login);
|
||||||
it('can logout', logout);
|
it('can logout', logout);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue