浏览代码

Add update tests

Johannes Zellner 8 年之前
父节点
当前提交
fdfbb88e5f
共有 2 个文件被更改,包括 115 次插入155 次删除
  1. 1 2
      README.md
  2. 114 153
      test/test.js

+ 1 - 2
README.md

@@ -31,6 +31,5 @@ The e2e tests are located in the `test/` folder and require [nodejs](http://node
 cd gogs-app/test
 cd gogs-app/test
 
 
 npm install
 npm install
-USERNAME=<cloudron username> PASSWORD=<cloudron password> mocha --bail test.js
+EMAIL=<cloudron user email> USERNAME=<cloudron username> PASSWORD=<cloudron password> mocha --bail test.js
 ```
 ```
-

+ 114 - 153
test/test.js

@@ -33,8 +33,8 @@ describe('Application life cycle test', function () {
     var app, reponame = 'testrepo';
     var app, reponame = 'testrepo';
     var username = process.env.USERNAME;
     var username = process.env.USERNAME;
     var password = process.env.PASSWORD;
     var password = process.env.PASSWORD;
+    var email = process.env.EMAIL;
     var TIMEOUT = process.env.TIMEOUT || 5000;
     var TIMEOUT = process.env.TIMEOUT || 5000;
-    var email, token;
 
 
     before(function (done) {
     before(function (done) {
         if (!process.env.USERNAME) return done(new Error('USERNAME env var not set'));
         if (!process.env.USERNAME) return done(new Error('USERNAME env var not set'));
@@ -55,6 +55,21 @@ describe('Application life cycle test', function () {
         done();
         done();
     });
     });
 
 
+    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.manage().deleteAllCookies();
+        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')), TIMEOUT).then(function () { done(); });
+    }
+
     function waitForUrl(url, done) {
     function waitForUrl(url, done) {
         browser.wait(function () {
         browser.wait(function () {
             return browser.getCurrentUrl().then(function (currentUrl) {
             return browser.getCurrentUrl().then(function (currentUrl) {
@@ -81,6 +96,33 @@ describe('Application life cycle test', function () {
         });
         });
     }
     }
 
 
+    function createRepo(done) {
+        browser.get('https://' + app.fqdn);
+        browser.findElement(by.linkText('New Repository')).click();
+        browser.wait(until.elementLocated(by.xpath('//*[contains(text(), "New Repository")]')), TIMEOUT);
+        browser.findElement(by.id('repo_name')).sendKeys(reponame);
+        browser.findElement(by.id('auto-init')).click();
+        browser.findElement(by.xpath('//button[contains(text(), "Create Repository")]')).click();
+        browser.wait(function () {
+            return browser.getCurrentUrl().then(function (url) {
+                return url === 'https://' + app.fqdn + '/' + username + '/' + reponame;
+            });
+        }, TIMEOUT).then(function () { done(); });
+    }
+
+    function cloneRepo() {
+        rimraf.sync(repodir);
+        var env = Object.create(process.env);
+        env.GIT_SSH_COMMAND = __dirname + '/git_ssh_wrapper.sh';
+        execSync('git clone ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git ' + repodir, { env: env });
+    }
+
+    function pushFile() {
+        var env = Object.create(process.env);
+        env.GIT_SSH_COMMAND = __dirname + '/git_ssh_wrapper.sh';
+        execSync('touch newfile && git add newfile && git commit -a -mx && git push ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + ' master', { env: env, cwd: repodir });
+    }
+
     function editFile(done) {
     function editFile(done) {
         browser.get('https://' + app.fqdn + '/' + username + '/' + reponame + '/_edit/master/newfile');
         browser.get('https://' + app.fqdn + '/' + username + '/' + reponame + '/_edit/master/newfile');
 
 
@@ -94,67 +136,20 @@ describe('Application life cycle test', function () {
         });
         });
     }
     }
 
 
-    xit('build app', function () {
-        execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
-    });
-
-    it('can login', function (done) {
-        var inspect = JSON.parse(execSync('cloudron inspect'));
-
-        superagent.post('https://' + inspect.apiEndpoint + '/api/v1/developer/login').send({
-            username: username,
-            password: password
-        }).end(function (error, result) {
-            if (error) return done(error);
-            if (result.statusCode !== 200) return done(new Error('Login failed with status ' + result.statusCode));
-
-            token = result.body.token;
-
-            superagent.get('https://' + inspect.apiEndpoint + '/api/v1/profile')
-                .query({ access_token: token }).end(function (error, result) {
-                if (error) return done(error);
-                if (result.statusCode !== 200) return done(new Error('Get profile failed with status ' + result.statusCode));
-
-                email = result.body.email;
-                done();
-            });
-        });
-    });
-
-
-    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);
+    function fileExists() {
+        expect(fs.existsSync(repodir + '/newfile')).to.be(true);
+    }
 
 
+    function checkCloneUrl(done) {
+        browser.get('https://' + app.fqdn + '/' + username + '/' + reponame);
+        browser.findElement(by.id('repo-clone-ssh')).click();
+        browser.findElement(by.id('repo-clone-url')).getAttribute('value').then(function (cloneUrl) {
+            expect(cloneUrl).to.be('ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git');
             done();
             done();
         });
         });
-    });
-
-    it('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')), TIMEOUT).then(function () { done(); });
-    });
-
-    it('can set avatar', setAvatar);
-    it('can get avatar', checkAvatar);
+    }
 
 
-    it('can add public key', function (done) {
+    function addPublicKey(done) {
         browser.get('https://' + app.fqdn + '/user/settings/ssh');
         browser.get('https://' + app.fqdn + '/user/settings/ssh');
         var publicKey = fs.readFileSync(__dirname + '/id_rsa.pub', 'utf8');
         var publicKey = fs.readFileSync(__dirname + '/id_rsa.pub', 'utf8');
 
 
@@ -163,62 +158,33 @@ describe('Application life cycle test', function () {
         browser.findElement(by.id('content')).sendKeys(publicKey.trim()); // #3480
         browser.findElement(by.id('content')).sendKeys(publicKey.trim()); // #3480
         browser.findElement(by.xpath('//button[contains(text(), "Add Key")]')).click();
         browser.findElement(by.xpath('//button[contains(text(), "Add Key")]')).click();
         browser.wait(until.elementLocated(by.xpath('//p[contains(text(), "added successfully!")]')), TIMEOUT).then(function () { done(); });
         browser.wait(until.elementLocated(by.xpath('//p[contains(text(), "added successfully!")]')), TIMEOUT).then(function () { done(); });
-    });
-
-    it('can create repo', function (done) {
-        browser.get('https://' + app.fqdn);
-        browser.findElement(by.linkText('New Repository')).click();
-        browser.wait(until.elementLocated(by.xpath('//*[contains(text(), "New Repository")]')), TIMEOUT);
-        browser.findElement(by.id('repo_name')).sendKeys(reponame);
-        browser.findElement(by.id('auto-init')).click();
-        browser.findElement(by.xpath('//button[contains(text(), "Create Repository")]')).click();
-        browser.wait(function () {
-            return browser.getCurrentUrl().then(function (url) {
-                return url === 'https://' + app.fqdn + '/' + username + '/' + reponame;
-            });
-        }, TIMEOUT).then(function () { done(); });
-    });
-
-    it('displays correct clone url', function (done) {
-        browser.get('https://' + app.fqdn + '/' + username + '/' + reponame);
-        browser.findElement(by.id('repo-clone-ssh')).click();
-        browser.findElement(by.id('repo-clone-url')).getAttribute('value').then(function (cloneUrl) {
-            expect(cloneUrl).to.be('ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git');
-            done();
-        });
-    });
+    }
 
 
-    it('can clone the url', function (done) {
-        var env = Object.create(process.env);
-        env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
-        execSync('git clone ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git ' + repodir, { env: env });
-        done();
+    xit('build app', function () {
+        execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
     });
     });
 
 
-    it('can add and push a file', function (done) {
-        var env = Object.create(process.env);
-        env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
-        execSync('touch newfile && git add newfile && git commit -a -mx && git push ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + ' master',
-                 { env: env, cwd: repodir });
-        rimraf.sync('/tmp/testrepo');
-        done();
+    it('install app', function () {
+        execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
     });
     });
 
 
+    it('can get app information', getAppInfo);
+    it('can login', login);
+    it('can set avatar', setAvatar);
+    it('can get avatar', checkAvatar);
+    it('can add public key', addPublicKey);
+    it('can create repo', createRepo);
+    it('displays correct clone url', checkCloneUrl);
+    it('can clone the url', cloneRepo);
+    it('can add and push a file', pushFile);
     it('can edit file', editFile);
     it('can edit file', editFile);
 
 
-    it('can restart app', function (done) {
-        execSync('cloudron restart');
-        done();
+    it('can restart app', function () {
+        execSync('cloudron restart --wait --app ' + app.id);
     });
     });
 
 
-    it('can clone the url', function (done) {
-        var env = Object.create(process.env);
-        env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
-        execSync('git clone ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git ' + repodir, { env: env });
-        expect(fs.existsSync(repodir + '/newfile')).to.be(true);
-        rimraf.sync(repodir);
-        done();
-    });
+    it('can clone the url', cloneRepo);
+    it('file exists in cloned repo', fileExists);
 
 
     it('backup app', function () {
     it('backup app', function () {
         execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
         execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
@@ -229,71 +195,66 @@ describe('Application life cycle test', function () {
     });
     });
 
 
     it('can get avatar', checkAvatar);
     it('can get avatar', checkAvatar);
-
-    it('can clone the url', function (done) {
-        var env = Object.create(process.env);
-        env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
-        execSync('git clone ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git ' + repodir, { env: env });
-        expect(fs.existsSync(repodir + '/newfile')).to.be(true);
-        rimraf.sync(repodir);
-        done();
-    });
+    it('can clone the url', cloneRepo);
+    it('file exists in cloned repo', fileExists);
 
 
     it('move to different location', function () {
     it('move to different location', function () {
-        browser.manage().deleteAllCookies();
-        execSync('cloudron configure --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');
-    });
-
-    it('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')), TIMEOUT).then(function () { done(); });
+        execSync('cloudron configure --wait --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
     });
     });
 
 
+    it('can get app information', getAppInfo);
+    it('can login', login);
     it('can get avatar', checkAvatar);
     it('can get avatar', checkAvatar);
-
-    it('displays correct clone url', function (done) {
-        browser.get('https://' + app.fqdn + '/' + username + '/' + reponame);
-        browser.findElement(by.id('repo-clone-ssh')).click();
-        browser.findElement(by.id('repo-clone-url')).getAttribute('value').then(function (cloneUrl) {
-            expect(cloneUrl).to.be('ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git');
-            done();
-        });
-    });
-
-    it('can clone the url', function (done) {
-        var env = Object.create(process.env);
-        env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
-        execSync('git clone ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git ' + repodir, { env: env });
-        expect(fs.existsSync(repodir + '/newfile')).to.be(true);
-        rimraf.sync(repodir);
-        done();
-    });
+    it('displays correct clone url', checkCloneUrl);
+    it('can clone the url', cloneRepo);
+    it('file exists in cloned repo', fileExists);
 
 
     it('uninstall app', function () {
     it('uninstall app', function () {
         execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
         execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
     });
     });
 
 
     // check if the _first_ login via email succeeds
     // check if the _first_ login via email succeeds
-    it('can login via email', function (done) {
+    it('can install app', function () {
         execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
         execSync('cloudron install --new --wait --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];
-        expect(app).to.be.an('object');
+    it('can get app information', getAppInfo);
 
 
+    it('can login via email', function (done) {
         browser.get('https://' + app.fqdn + '/user/login');
         browser.get('https://' + app.fqdn + '/user/login');
         browser.findElement(by.id('user_name')).sendKeys(email);
         browser.findElement(by.id('user_name')).sendKeys(email);
         browser.findElement(by.id('password')).sendKeys(password);
         browser.findElement(by.id('password')).sendKeys(password);
         browser.findElement(by.tagName('form')).submit();
         browser.findElement(by.tagName('form')).submit();
-        browser.wait(until.elementLocated(by.linkText('Dashboard')), TIMEOUT).then(function () {
-            execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
-            done();
-        });
+        browser.wait(until.elementLocated(by.linkText('Dashboard')), TIMEOUT).then(function () { done(); });
+    });
+
+    it('uninstall app', function () {
+        execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
+    });
+
+    // test update
+    it('can install app', function () {
+        execSync('cloudron install --new --wait --appstore-id ' + app.manifest.id + ' --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
+    });
+
+    it('can get app information', getAppInfo);
+    it('can login', login);
+    it('can set avatar', setAvatar);
+    it('can get avatar', checkAvatar);
+    it('can add public key', addPublicKey);
+    it('can create repo', createRepo);
+    it('can clone the url', cloneRepo);
+    it('can add and push a file', pushFile);
+
+    it('can update', function () {
+        execSync('cloudron install --wait --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
+    });
+
+    it('can get avatar', checkAvatar);
+    it('can clone the url', cloneRepo);
+    it('file exists in cloned repo', fileExists);
+
+    it('uninstall app', function () {
+        execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
     });
     });
 });
 });