208 lines
9.2 KiB
JavaScript
208 lines
9.2 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/* jshint esversion: 8 */
|
|
/* global describe */
|
|
/* global before */
|
|
/* global after */
|
|
/* global it */
|
|
/* global xit */
|
|
|
|
'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');
|
|
|
|
describe('Application life cycle test', function () {
|
|
this.timeout(0);
|
|
|
|
const LOCATION = 'test';
|
|
const TEST_TIMEOUT = 10000;
|
|
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
|
|
const BUCKET = 'cloudrontestbucket';
|
|
const username = process.env.USERNAME;
|
|
const password = process.env.PASSWORD;
|
|
|
|
let browser, app;
|
|
|
|
before(function (done) {
|
|
if (!process.env.PASSWORD) return done(new Error('PASSWORD env var not set'));
|
|
if (!process.env.USERNAME) return done(new Error('USERNAME env var not set'));
|
|
|
|
browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build();
|
|
done();
|
|
});
|
|
|
|
after(function () {
|
|
browser.quit();
|
|
});
|
|
|
|
function sleep(millis) {
|
|
return new Promise(resolve => setTimeout(resolve, millis));
|
|
}
|
|
|
|
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(accessKey='minioadmin', secretKey='minioadmin') {
|
|
await browser.get(`https://${app.fqdn}/login`);
|
|
await waitForElement(By.id('accessKey'));
|
|
await browser.findElement(By.id('accessKey')).sendKeys(accessKey);
|
|
await browser.findElement(By.id('secretKey')).sendKeys(secretKey);
|
|
await browser.findElement(By.xpath('//button[@type="submit"]/span[text()="Login"]')).click();
|
|
await waitForElement(By.xpath(`//div/span[contains(text(), "Dashboard")]`));
|
|
}
|
|
|
|
async function old_login(accessKey='minioadmin', secretKey='minioadmin') {
|
|
await browser.get(`https://${app.fqdn}/minio/login`);
|
|
await waitForElement(By.id('accessKey'));
|
|
await browser.findElement(By.id('accessKey')).sendKeys(accessKey);
|
|
await browser.findElement(By.id('secretKey')).sendKeys(secretKey);
|
|
await browser.findElement(By.xpath('//button[@type="submit"]')).click();
|
|
await waitForElement(By.xpath(`//input[@placeholder="Search Buckets..."]`));
|
|
}
|
|
|
|
async function logout() {
|
|
await browser.get(`https://${app.fqdn}/`);
|
|
await waitForElement(By.xpath(`//div/span[contains(text(), "Dashboard")]`));
|
|
await browser.findElement(By.xpath('//div/span[contains(text(), "Logout")]')).click();
|
|
await waitForElement(By.id('accessKey'));
|
|
}
|
|
|
|
async function old_logout() {
|
|
await browser.get(`https://${app.fqdn}/`);
|
|
await waitForElement(By.xpath(`//input[@placeholder="Search Buckets..."]`));
|
|
await browser.findElement(By.xpath('//div/button[@id="top-right-menu"]')).click();
|
|
await browser.findElement(By.xpath('//ul/li/a[@id="logout"]')).click();
|
|
await waitForElement(By.id('accessKey'));
|
|
}
|
|
|
|
async function addBucket() {
|
|
await browser.get(`https://${app.fqdn}/`);
|
|
await waitForElement(By.xpath('//div/span[contains(text(), "Bucket")]'));
|
|
await browser.findElement(By.xpath('//div/span[contains(text(), "Bucket")]')).click();
|
|
await waitForElement(By.xpath('//span[text()="Create Bucket"]'));
|
|
await browser.findElement(By.xpath('//span[text()="Create Bucket"]')).click();
|
|
await browser.findElement(By.xpath('//input[@id="bucket-name"]')).sendKeys(BUCKET);
|
|
await browser.findElement(By.xpath('//button[@type="submit"]/span[text()="Save"]')).click();
|
|
await waitForElement(By.xpath(`//div/span[contains(text(), "${BUCKET}")]`));
|
|
await browser.findElement(By.xpath(`//div/span[contains(text(), "${BUCKET}")]`));
|
|
}
|
|
|
|
async function old_addBucket() {
|
|
await browser.get(`https://${app.fqdn}/`);
|
|
await waitForElement(By.xpath(`//input[@placeholder="Search Buckets..."]`));
|
|
await browser.findElement(By.xpath('//div/button[@id="fe-action-toggle"]')).click();
|
|
await browser.findElement(By.xpath('//ul/a[@id="show-make-bucket"]')).click();
|
|
await browser.findElement(By.xpath('//input[@placeholder="Bucket Name"]')).sendKeys(BUCKET);
|
|
await browser.findElement(By.xpath('//*[@class="modal-body"]/form')).submit();
|
|
await waitForElement(By.xpath(`//*[@class="main"]/a[text()="${BUCKET}"]`));
|
|
}
|
|
|
|
async function checkBucket() {
|
|
await browser.get(`https://${app.fqdn}/`);
|
|
await waitForElement(By.xpath(`//div/span[contains(text(), "Dashboard")]`));
|
|
await browser.findElement(By.xpath('//div/span[contains(text(), "Bucket")]')).click();
|
|
await waitForElement(By.xpath(`//div/span[contains(text(), "${BUCKET}")]`));
|
|
await browser.findElement(By.xpath(`//div/span[contains(text(), "${BUCKET}")]`));
|
|
}
|
|
|
|
async function old_checkBucket() {
|
|
await browser.get(`https://${app.fqdn}/`);
|
|
await waitForElement(By.xpath(`//input[@placeholder="Search Buckets..."]`));
|
|
await waitForElement(By.xpath(`//*[@class="main"]/a[text()="${BUCKET}"]`));
|
|
}
|
|
|
|
async function openSettings() {
|
|
await browser.get(`https://${app.fqdn}/`);
|
|
await waitForElement(By.xpath(`//div/span[contains(text(), "Dashboard")]`));
|
|
await browser.findElement(By.xpath('//div/span[contains(text(), "Account")]')).click();
|
|
await waitForElement(By.xpath(`//button/span[text()="Change Password"]`));
|
|
await browser.findElement(By.xpath('//button/span[text()="Change Password"]'));
|
|
}
|
|
|
|
async function old_openSettings() {
|
|
await browser.get(`https://${app.fqdn}/`);
|
|
await waitForElement(By.xpath(`//input[@placeholder="Search Buckets..."]`));
|
|
await browser.findElement(By.xpath('//div/button[@id="top-right-menu"]')).click();
|
|
await waitForElement(By.xpath('//ul/li/a[contains(text(), "Change Password")]'));
|
|
await browser.findElement(By.xpath('//ul/li/a[contains(text(), "Change Password")]'));
|
|
}
|
|
|
|
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, 'minioadmin', 'minioadmin'));
|
|
it('can add bucket', addBucket);
|
|
it('can open settings', openSettings);
|
|
it('can logout', logout);
|
|
|
|
it('can change credentials', function () {
|
|
execSync(`cloudron exec --app ${app.id} -- /app/code/minio-credentials set minioakey minioskey`, EXEC_ARGS);
|
|
});
|
|
|
|
it('can restart app', function () { execSync(`cloudron restart --app ${app.id}`, EXEC_ARGS); });
|
|
|
|
it('can login', login.bind(null, 'minioakey', 'minioskey'));
|
|
it('has bucket', checkBucket);
|
|
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 --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 login', login.bind(null, 'minioakey', 'minioskey'));
|
|
it('has bucket', checkBucket);
|
|
it('can open settings', openSettings);
|
|
it('can logout', logout);
|
|
|
|
it('move to different location', function () {
|
|
browser.manage().deleteAllCookies();
|
|
execSync('cloudron configure --location ' + LOCATION + '2', EXEC_ARGS);
|
|
});
|
|
it('can get app information', getAppInfo);
|
|
|
|
it('can login', login.bind(null, 'minioakey', 'minioskey'));
|
|
it('has bucket', checkBucket);
|
|
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.minio.cloudronapp --location ' + LOCATION, EXEC_ARGS); });
|
|
it('can get app information', getAppInfo);
|
|
|
|
it('can login', old_login.bind(null, 'minioadmin', 'minioadmin'));
|
|
it('can add buckets', old_addBucket);
|
|
it('can logout', old_logout);
|
|
it('can update', function () { execSync(`cloudron update --app ${LOCATION} --no-wait`, EXEC_ARGS); });
|
|
it('can enable API Port', function () { execSync(`cloudron configure --app ${LOCATION} -p API_PORT=9000 -l ${LOCATION} `, EXEC_ARGS); });
|
|
it('can get app information', getAppInfo);
|
|
|
|
it('can login', login.bind(null, 'minioadmin', 'minioadmin'));
|
|
it('has bucket', checkBucket);
|
|
it('can logout', logout);
|
|
|
|
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
|
|
});
|
|
|