prometheus-server-app/test/test.js
Johannes Zellner dd9acc3618 Fixup tests
2024-05-10 14:48:19 +02:00

130 lines
4.4 KiB
JavaScript
Executable file

#!/usr/bin/env node
/* jshint esversion: 8 */
/* global describe */
/* global before */
/* global after */
/* global it */
'use strict';
require('chromedriver');
var execSync = require('child_process').execSync,
expect = require('expect.js'),
path = require('path'),
{ Builder, By, Key, until } = require('selenium-webdriver'),
{ Options } = require('selenium-webdriver/chrome');
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);
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 password = process.env.PASSWORD;
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() {
var inspect = JSON.parse(execSync('cloudron inspect'));
app = inspect.apps.filter(function (a) { return a.location.indexOf(LOCATION) === 0; })[0];
expect(app).to.be.an('object');
}
async function login(session = true) {
await browser.get(`https://${app.fqdn}`);
await waitForElement(By.id('loginProceedButton'));
await browser.findElement(By.id('loginProceedButton')).click();
if (!session) {
await waitForElement(By.id('inputUsername'));
await browser.findElement(By.id('inputUsername')).sendKeys(username);
await browser.findElement(By.id('inputPassword')).sendKeys(password);
await browser.findElement(By.id('loginSubmitButton')).click();
}
await waitForElement(By.xpath('//a[text()="Alerts"]'));
}
async function logout() {
await browser.get(`https://${app.fqdn}/logout`);
await waitForElement(By.id('loginProceedButton'));
}
async function loadApp() {
await browser.get(`https://${app.fqdn}`);
await waitForElement(By.xpath('//a[text()="Alerts"]'));
}
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.bind(null, false));
it('can load app', loadApp);
it('can restart app', function () { execSync(`cloudron restart --app ${app.id}`, EXEC_ARGS); });
it('can load app', loadApp);
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 --app ${app.id}`));
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
execSync('cloudron install --location ' + LOCATION, EXEC_ARGS);
getAppInfo();
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, EXEC_ARGS);
});
it('can load app', loadApp);
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 load app', loadApp);
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 login', login);
it('can load app', loadApp);
it('can update', function () { execSync(`cloudron update --app ${app.id}`, EXEC_ARGS); });
it('can load app', loadApp);
it('can logout', logout);
it('uninstall app', function () { execSync(`cloudron uninstall --app ${app.id}`, EXEC_ARGS); });
});