Add tests

This commit is contained in:
Girish Ramakrishnan 2020-12-10 21:27:08 -08:00
parent d680aca62d
commit 7848ad4753
5 changed files with 1691 additions and 5 deletions

View file

@ -9,7 +9,8 @@
"httpPort": 9090, "httpPort": 9090,
"icon": "logo.png", "icon": "logo.png",
"addons": { "addons": {
"localstorage": {} "localstorage": {},
"proxyAuth": {}
}, },
"manifestVersion": 2, "manifestVersion": 2,
"website": "https://prometheus.io/", "website": "https://prometheus.io/",
@ -17,7 +18,7 @@
"tags": [ "metrics", "analytics", "graphite", "collect", "graphs" ], "tags": [ "metrics", "analytics", "graphite", "collect", "graphs" ],
"changelog": "file://CHANGELOG", "changelog": "file://CHANGELOG",
"documentationUrl": "https://docs.cloudron.io/apps/prometheus-server/", "documentationUrl": "https://docs.cloudron.io/apps/prometheus-server/",
"minBoxVersion": "5.5.0", "minBoxVersion": "6.0.0",
"forumUrl": "https://forum.cloudron.io/category/112/prometheus", "forumUrl": "https://forum.cloudron.io/category/112/prometheus",
"mediaLinks": [ "mediaLinks": [
"https://screenshots.cloudron.io/io.prometheus.cloudronapp/1.png", "https://screenshots.cloudron.io/io.prometheus.cloudronapp/1.png",

View file

@ -4,12 +4,12 @@ set -eu
mkdir -p /app/data/runtime /app/data/config mkdir -p /app/data/runtime /app/data/config
chown -R cloudron:cloudron /app/data
if [[ ! -f /app/data/config/prometheus.yml ]]; then if [[ ! -f /app/data/config/prometheus.yml ]]; then
echo "=> Creating config file on first run" echo "=> Creating config file on first run"
sudo -u cloudron cp -n /app/code/prometheus.yml /app/data/config/prometheus.yml cp /app/code/prometheus.yml /app/data/config/prometheus.yml
fi fi
chown -R cloudron:cloudron /app/data
echo "=> Starting Prometheus" echo "=> Starting Prometheus"
exec /usr/local/bin/gosu cloudron:cloudron /app/code/prometheus --config.file=/app/data/config/prometheus.yml --storage.tsdb.path=/app/data/runtime exec /usr/local/bin/gosu cloudron:cloudron /app/code/prometheus --config.file=/app/data/config/prometheus.yml --storage.tsdb.path=/app/data/runtime

1535
test/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

21
test/package.json Normal file
View file

@ -0,0 +1,21 @@
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "test.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"expect.js": "^0.3.1",
"mocha": "^8.2.1",
"selenium-server-standalone-jar": "^3.141.59",
"selenium-webdriver": "^3.6.0",
"superagent": "^6.1.0"
},
"dependencies": {
"chromedriver": "^87.0.2"
}
}

129
test/test.js Executable file
View file

@ -0,0 +1,129 @@
#!/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); });
});