test.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/usr/bin/env node
  2. 'use strict';
  3. var execSync = require('child_process').execSync,
  4. expect = require('expect.js'),
  5. path = require('path'),
  6. util = require('util'),
  7. webdriver = require('selenium-webdriver');
  8. var by = webdriver.By,
  9. until = webdriver.until;
  10. process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
  11. if (!process.env.USERNAME || !process.env.PASSWORD) {
  12. console.log('USERNAME and PASSWORD env vars need to be set');
  13. process.exit(1);
  14. }
  15. describe('Application life cycle test', function () {
  16. this.timeout(0);
  17. var chrome = require('selenium-webdriver/chrome');
  18. var server, browser = new chrome.Driver();
  19. before(function (done) {
  20. var seleniumJar= require('selenium-server-standalone-jar');
  21. var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
  22. server = new SeleniumServer(seleniumJar.path, { port: 4444 });
  23. server.start();
  24. done();
  25. });
  26. after(function (done) {
  27. browser.quit();
  28. server.stop();
  29. done();
  30. });
  31. var LOCATION = 'test';
  32. var TEST_TIMEOUT = 50000;
  33. var app;
  34. function waitForElement(elem, callback) {
  35. browser.wait(until.elementLocated(elem), TEST_TIMEOUT).then(function () {
  36. browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT).then(function () {
  37. callback();
  38. });
  39. });
  40. }
  41. function welcomePage(callback) {
  42. browser.get('https://' + app.fqdn);
  43. waitForElement(by.xpath('//*[text()="Cloudron LAMP App"]'), function () {
  44. waitForElement(by.xpath('//*[text()="PHP Version 7.0.15-0ubuntu0.16.04.2"]'), callback);
  45. });
  46. }
  47. function uploadedFileExists(callback) {
  48. browser.get('https://' + app.fqdn + '/test.php');
  49. waitForElement(by.xpath('//*[text()="this works"]'), function () {
  50. waitForElement(by.xpath('//*[text()="' + app.fqdn + '"]'), callback);
  51. });
  52. }
  53. xit('build app', function () {
  54. execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  55. });
  56. it('install app', function () {
  57. execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  58. });
  59. it('can get app information', function () {
  60. var inspect = JSON.parse(execSync('cloudron inspect'));
  61. app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
  62. expect(app).to.be.an('object');
  63. });
  64. it('can view welcome page', welcomePage);
  65. it('can upload file with sftp', function () {
  66. // remove from known hosts in case this test was run on other apps with the same domain already
  67. execSync(util.format('sed -i \'/%s/d\' -i ~/.ssh/known_hosts', app.fqdn));
  68. execSync(util.format('lftp sftp://%s:%s@%s:%s -e "set sftp:auto-confirm yes; cd public/; put test.php; bye"', process.env.USERNAME, process.env.PASSWORD, app.fqdn, app.portBindings.SFTP_PORT));
  69. });
  70. it('can get uploaded file', uploadedFileExists);
  71. it('backup app', function () {
  72. execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  73. });
  74. it('restore app', function () {
  75. execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  76. });
  77. it('can get uploaded file', uploadedFileExists);
  78. it('move to different location', function () {
  79. browser.manage().deleteAllCookies();
  80. execSync('cloudron configure --wait --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  81. var inspect = JSON.parse(execSync('cloudron inspect'));
  82. app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
  83. expect(app).to.be.an('object');
  84. });
  85. it('can get uploaded file', uploadedFileExists);
  86. it('uninstall app', function () {
  87. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  88. });
  89. });