瀏覽代碼

initial tests

Girish Ramakrishnan 9 年之前
父節點
當前提交
68610f5820
共有 2 個文件被更改,包括 140 次插入0 次删除
  1. 21 0
      test/package.json
  2. 119 0
      test/test.js

+ 21 - 0
test/package.json

@@ -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": {
+    "ejs": "^2.3.4",
+    "expect.js": "^0.3.1",
+    "mkdirp": "^0.5.1",
+    "mocha": "^2.3.4",
+    "rimraf": "^2.4.4",
+    "selenium-server-standalone-jar": "^2.47.1",
+    "selenium-webdriver": "^2.48.2",
+    "superagent": "^1.4.0"
+  }
+}

+ 119 - 0
test/test.js

@@ -0,0 +1,119 @@
+#!/usr/bin/env node
+
+/* jslint node:true */
+/* global it:false */
+/* global xit:false */
+/* global describe:false */
+/* global before:false */
+/* global after:false */
+
+'use strict';
+
+var execSync = require('child_process').execSync,
+    ejs = require('ejs'),
+    expect = require('expect.js'),
+    fs = require('fs'),
+    mkdirp = require('mkdirp'),
+    path = require('path'),
+    rimraf = require('rimraf'),
+    superagent = require('superagent'),
+    webdriver = require('selenium-webdriver');
+
+var by = require('selenium-webdriver').By,
+    until = require('selenium-webdriver').until;
+
+process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
+
+describe('Application life cycle test', function () {
+    this.timeout(0);
+    var firefox = require('selenium-webdriver/firefox');
+    var server, browser = new firefox.Driver();
+    var LOCATION = 'wptest';
+    var app;
+    var username = process.env.USERNAME;
+    var password = process.env.PASSWORD;
+
+    before(function (done) {
+        if (!process.env.USERNAME) return done(new Error('USERNAME env var not set'));
+        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', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
+    });
+
+    it('install app', function () {
+        execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
+    });
+
+    it('can get app information', function () {
+        var inspect = JSON.parse(execSync('cloudron inspect'));
+
+        app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
+
+        expect(app).to.be.an('object');
+    });
+
+    it('can get the main page', function (done) {
+        superagent.get('https://' + app.fqdn).end(function (error, result) {
+            expect(error).to.be(null);
+            expect(result.status).to.eql(200);
+
+            done();
+        });
+    });
+
+    xit('can login', function (done) {
+        browser.get('https://' + app.fqdn + '/user/login');
+        browser.findElement(by.id('user_name')).sendKeys(username);
+        browser.findElement(by.id('password')).sendKeys(password);
+        browser.findElement(by.tagName('form')).submit();
+        browser.wait(until.elementLocated(by.linkText('Dashboard')), 4000).then(function () { done(); });
+    });
+
+    it('can restart app', function (done) {
+        execSync('cloudron restart');
+        done();
+    });
+
+    it('backup app', function () {
+        execSync('cloudron backup --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
+    });
+
+    it('restore app', function () {
+        execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
+    });
+
+    it('move to different location', function () {
+        browser.manage().deleteAllCookies();
+        execSync('cloudron install --location ' + LOCATION + '2', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
+        var inspect = JSON.parse(execSync('cloudron inspect'));
+        app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
+        expect(app).to.be.an('object');
+    });
+
+    xit('can login', function (done) {
+        browser.get('https://' + app.fqdn + '/user/login');
+        browser.findElement(by.id('user_name')).sendKeys(username);
+        browser.findElement(by.id('password')).sendKeys(password);
+        browser.findElement(by.tagName('form')).submit();
+        browser.wait(until.elementLocated(by.linkText('Dashboard')), 4000).then(function () { done(); });
+    });
+
+    it('uninstall app', function () {
+        execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
+    });
+});