From fcbd5bce4d493b3622fefa83c45d562b0aa34cfe Mon Sep 17 00:00:00 2001 From: Ilya Radchenko Date: Thu, 23 Oct 2014 08:12:20 -0400 Subject: [PATCH] Cleanup --- config/config.html | 79 +++++++++++++++++++++++---------------------- config/config.js | 23 +++++++------ package.json | 2 +- test/worker_test.js | 53 ++++++++++++++++-------------- webapp.js | 68 +++++++++++++++++++------------------- worker.js | 13 +++++--- 6 files changed, 123 insertions(+), 115 deletions(-) diff --git a/config/config.html b/config/config.html index c9a6041..99c2ef3 100644 --- a/config/config.html +++ b/config/config.html @@ -1,45 +1,46 @@
-

Template Config Page

- -
-
-

- These are some messages for demonstrating how the plugin saves config data and reports it during the test process. - Each message used slightly differently, so see `worker.js` for different ways to execute actions using config data -

-

Environment

-
-
- -
+

Template Config Page

+

+ +

+ These are some messages for demonstrating how the plugin saves config data and reports it during the test process. + Each message used slightly differently, so see `worker.js` for different ways to execute actions using config data +

+ +

Environment

+
+
+
-
-

Prepare

-
-
- -
+

+ +

Prepare

+
+
+
-
-

Test

-
-
- -
+

+ +

Test

+
+
+
-
-

Deploy

-
-
- -
+

+ +

Deploy

+
+
+
-
-

Cleanup

-
-
- -
+

+ +

Cleanup

+
+
+
- -
\ No newline at end of file +
+ + +
diff --git a/config/config.js b/config/config.js index 0345df8..d423ce6 100644 --- a/config/config.js +++ b/config/config.js @@ -1,18 +1,22 @@ +'use strict'; + var app = window.app; +var configDefaults = { + environment: 'Hi from `environment`', + prepare: 'Hi from `prepare`', + test: 'Hi from `test`', + deploy: 'Hi from `deploy`', + cleanup: 'Hi from `cleanup`' +}; + /* * $scope.configs, $scope.branch and $scope.pluginConfig, among others are available from the parent scope * */ -app.controller('TemplateCtrl', ['$scope', function ($scope) { +app.controller('TemplateController', ['$scope', function ($scope) { $scope.saving = false; $scope.$watch('configs[branch.name].template.config', function (value) { - $scope.config = value || { - environment: 'Hi from `environment`', - prepare: 'Hi from `prepare`', - test: 'Hi from `test`', - deploy: 'Hi from `deploy`', - cleanup: 'Hi from `cleanup`' - }; + $scope.config = value || configDefaults; }); $scope.save = function () { @@ -21,5 +25,4 @@ app.controller('TemplateCtrl', ['$scope', function ($scope) { $scope.saving = false; }); }; - -}]); \ No newline at end of file +}]); diff --git a/package.json b/package.json index d960227..0a1df2c 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "webapp": "webapp.js", "icon": "icon.png", "config": { - "controller": "TemplateCtrl" + "controller": "TemplateController" } }, "devDependencies": { diff --git a/test/worker_test.js b/test/worker_test.js index 7ddd9c9..dba981b 100644 --- a/test/worker_test.js +++ b/test/worker_test.js @@ -1,48 +1,52 @@ +'use strict'; + var sinon = require('sinon'); var chai = require('chai'); -var expect = chai.expect; -chai.use(require('sinon-chai')); +var sinonChai = require('sinon-chai'); var Worker = require('../worker.js'); var WebApp = require('../webapp.js'); -describe("template worker test example", function() { - var work = null; - var io = null; - var context = null; - var config = null; - var job = null; - var exitCode = null; +var expect = chai.expect; + +chai.use(sinonChai); - var prepareWorker = function(done) { +describe('template worker test example', function () { + var work, io, context, config, job, exitCode; + + function prepareWorker(done) { context = {}; io = { on: sinon.stub().yields('123', { exitCode: exitCode }), removeListener: sinon.stub(), emit: sinon.stub() }; - Worker.init(config, job, sinon.stub(), function(err, res) { - work = function(){ + + Worker.init(config, job, sinon.stub(), function (err, res) { + work = function () { return res; }; - if (done) done(); - }) - }; - beforeEach(function(done) { + if (done) { + done(); + } + }); + } + + beforeEach(function (done) { exitCode = 0; job = { - project: { name: "strider-template" }, - ref: { branch: "master" }, - _id: "123", + project: { name: 'strider-template' }, + ref: { branch: 'master' }, + _id: '123', trigger: { - type: "manual" + type: 'manual' } }; - process.env.strider_server_name = "http://example.com"; + process.env.strider_server_name = 'http://example.com'; config = { - environment: "test message", - prepare: "test message" + environment: 'test message', + prepare: 'test message' }; //_.each(schema, function(v,k) { config[k] = v.default }); //config.token = 'token'; @@ -51,7 +55,7 @@ describe("template worker test example", function() { prepareWorker(done); }); - it("should set up the phase actions properly", function() { + it('should set up the phase actions properly', function () { var setup = work(); //environment returns a string expect(setup.environment).to.equal('echo "test message"'); @@ -62,5 +66,4 @@ describe("template worker test example", function() { //test returns a function expect(typeof setup.test).to.equal('function'); }); - }); diff --git a/webapp.js b/webapp.js index 6dfec4c..702a710 100644 --- a/webapp.js +++ b/webapp.js @@ -1,37 +1,35 @@ module.exports = { - // mongoose schema, if you need project-specific config - config: { - "template": { - environment: {type: String, default: 'Hi from `environment`'}, - prepare: {type: String, default: 'Hi from `prepare`'}, - test: {type: String, default: 'Hi from `test`'}, - deploy: {type: String, default: 'Hi from `deploy`'}, - cleanup: {type: String, default: 'Hi from `cleanup`'} - } - }, - // Define project-specific routes - // all routes created here are namespaced within /:org/:repo/api/:pluginid - // req.project is the current project - // req.accessLevel is the current user's access level for the project - // 0 - anonymous, 1 - authed, 2 - admin / collaborator - // req.user is the current user - // req.pluginConfig() -> get the config for this plugin - // req.pluginConfig(config, cb(err)) -> set the config for this plugin - routes: function (app, context) { - }, - // Define global routes - // all routes namespaced within /ext/:pluginid - // req.user is the current user - // req.user.account_level can be used for authorization - // 0 - anonymous, 1 - authed, 2 - admin / collaborator - globalRoutes: function (app, context) { - }, - // Listen for global events - // all job-local events that begin with `plugin.` are proxied to - // the main strider eventemitter, so you can listen for them here. - // Other events include `job.new`, `job.done` and `browser.update`. - listen: function (emitter, context) { + // mongoose schema, if you need project-specific config + config: { + template: { + environment: { type: String, default: 'Hi from `environment`' }, + prepare: { type: String, default: 'Hi from `prepare`' }, + test: { type: String, default: 'Hi from `test`' }, + deploy: { type: String, default: 'Hi from `deploy`' }, + cleanup: { type: String, default: 'Hi from `cleanup`' } } - - -}; \ No newline at end of file + }, + // Define project-specific routes + // all routes created here are namespaced within /:org/:repo/api/:pluginid + // req.project is the current project + // req.accessLevel is the current user's access level for the project + // 0 - anonymous, 1 - authed, 2 - admin / collaborator + // req.user is the current user + // req.pluginConfig() -> get the config for this plugin + // req.pluginConfig(config, cb(err)) -> set the config for this plugin + routes: function (app, context) { + }, + // Define global routes + // all routes namespaced within /ext/:pluginid + // req.user is the current user + // req.user.account_level can be used for authorization + // 0 - anonymous, 1 - authed, 2 - admin / collaborator + globalRoutes: function (app, context) { + }, + // Listen for global events + // all job-local events that begin with `plugin.` are proxied to + // the main strider eventemitter, so you can listen for them here. + // Other events include `job.new`, `job.done` and `browser.update`. + listen: function (emitter, context) { + } +}; diff --git a/worker.js b/worker.js index 18f0340..3a93c56 100644 --- a/worker.js +++ b/worker.js @@ -1,9 +1,12 @@ +'use strict'; + /* Functions for demonstration purposes only */ -var checkSomething = function(context, callback){ +function checkSomething(context, callback){ //Do something here, then call back callback(true); }; -var doThings = function(callback){ + +function doThings(callback){ callback(null); }; @@ -14,7 +17,7 @@ module.exports = { // job: see strider-runner-core for a description of that object // context: currently only defines "dataDir" // cb(err, initializedPlugin) - init: function (config, job, context, cb) { + init: function (config, job, context, cb) { return cb(null, { // any extra env variables. Will be available during all phases env: {}, @@ -54,6 +57,7 @@ module.exports = { // positives. return done(null, false); } + doThings(function (err) { done(err, true); }); @@ -61,7 +65,6 @@ module.exports = { }, deploy: 'echo "' + config.deploy + '"', cleanup: 'echo "' + config.cleanup + '"' - }); }, // this is only used if there is _no_ plugin configuration for a @@ -70,4 +73,4 @@ module.exports = { filename: 'package.json', exists: true } -}; \ No newline at end of file +};