test.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/usr/bin/env node
  2. 'use strict';
  3. var execSync = require('child_process').execSync,
  4. ejs = require('ejs'),
  5. expect = require('expect.js'),
  6. fs = require('fs'),
  7. mkdirp = require('mkdirp'),
  8. path = require('path'),
  9. rimraf = require('rimraf'),
  10. superagent = require('superagent'),
  11. webdriver = require('selenium-webdriver');
  12. var by = require('selenium-webdriver').By,
  13. until = require('selenium-webdriver').until;
  14. process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
  15. describe('Application life cycle test', function () {
  16. this.timeout(0);
  17. var firefox = require('selenium-webdriver/firefox');
  18. var server, browser = new firefox.Driver();
  19. var LOCATION = 'gogstest';
  20. var repodir = '/tmp/testrepo';
  21. var app, reponame = 'testrepo';
  22. var username = process.env.USERNAME;
  23. var password = process.env.PASSWORD;
  24. before(function (done) {
  25. if (!process.env.USERNAME) return done(new Error('USERNAME env var not set'));
  26. if (!process.env.PASSWORD) return done(new Error('PASSWORD env var not set'));
  27. var seleniumJar= require('selenium-server-standalone-jar');
  28. var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
  29. server = new SeleniumServer(seleniumJar.path, { port: 4444 });
  30. server.start();
  31. done();
  32. });
  33. after(function (done) {
  34. browser.quit();
  35. server.stop();
  36. rimraf.sync(repodir);
  37. done();
  38. });
  39. xit('build app', function () {
  40. execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  41. });
  42. it('install app', function () {
  43. execSync('cloudron install --new --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  44. });
  45. it('can get app information', function () {
  46. var inspect = JSON.parse(execSync('cloudron inspect'));
  47. app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
  48. expect(app).to.be.an('object');
  49. });
  50. it('can get the main page', function (done) {
  51. superagent.get('https://' + app.fqdn).end(function (error, result) {
  52. expect(error).to.be(null);
  53. expect(result.status).to.eql(200);
  54. done();
  55. });
  56. });
  57. it('can login', function (done) {
  58. browser.get('https://' + app.fqdn + '/user/login');
  59. browser.findElement(by.id('user_name')).sendKeys(username);
  60. browser.findElement(by.id('password')).sendKeys(password);
  61. browser.findElement(by.tagName('form')).submit();
  62. browser.wait(until.elementLocated(by.linkText('Dashboard')), 4000).then(function () { done(); });
  63. });
  64. it('can add public key', function (done) {
  65. browser.get('https://' + app.fqdn + '/user/settings/ssh');
  66. var publicKey = fs.readFileSync(__dirname + '/id_rsa.pub', 'utf8');
  67. browser.findElement(by.xpath('//div[text()="Add Key"]')).click();
  68. browser.findElement(by.id('title')).sendKeys('testkey');
  69. browser.findElement(by.id('content')).sendKeys(publicKey);
  70. browser.findElement(by.xpath('//button[contains(text(), "Add Key")]')).click();
  71. browser.wait(until.elementLocated(by.xpath('//p[contains(text(), "added successfully!")]')), 4000).then(function () { done(); });
  72. });
  73. it('can create repo', function (done) {
  74. browser.get('https://' + app.fqdn);
  75. browser.findElement(by.linkText('New Repository')).click();
  76. browser.wait(until.elementLocated(by.xpath('//*[contains(text(), "New Repository")]')), 4000);
  77. browser.findElement(by.id('repo_name')).sendKeys(reponame);
  78. browser.findElement(by.id('auto-init')).click();
  79. browser.findElement(by.xpath('//button[contains(text(), "Create Repository")]')).click();
  80. browser.wait(function () {
  81. return browser.getCurrentUrl().then(function (url) {
  82. return url === 'https://' + app.fqdn + '/' + username + '/' + reponame;
  83. });
  84. }, 4000).then(function () { done(); });
  85. });
  86. it('displays correct clone url', function (done) {
  87. browser.get('https://' + app.fqdn + '/' + username + '/' + reponame);
  88. browser.findElement(by.id('repo-clone-url')).getAttribute('value').then(function (cloneUrl) {
  89. expect(cloneUrl).to.be('ssh://cloudron@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git');
  90. done();
  91. });
  92. });
  93. it('can clone the url', function (done) {
  94. var env = Object.create(process.env);
  95. env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
  96. execSync('git clone ssh://cloudron@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git ' + repodir, { env: env });
  97. done();
  98. });
  99. it('can add and push a file', function (done) {
  100. var env = Object.create(process.env);
  101. env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
  102. execSync('touch newfile && git add newfile && git commit -a -mx && git push ssh://cloudron@' + app.fqdn + ':29418/' + username + '/' + reponame + ' master',
  103. { env: env, cwd: repodir });
  104. rimraf.sync('/tmp/testrepo');
  105. done();
  106. });
  107. it('backup app', function () {
  108. execSync('cloudron backup --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  109. });
  110. it('restore app', function () {
  111. execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  112. });
  113. it('can clone the url', function (done) {
  114. var env = Object.create(process.env);
  115. env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
  116. execSync('git clone ssh://cloudron@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git ' + repodir, { env: env });
  117. expect(fs.existsSync(repodir + '/newfile')).to.be(true);
  118. rimraf.sync(repodir);
  119. done();
  120. });
  121. it('uninstall app', function () {
  122. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  123. });
  124. });