Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Radchenko committed Oct 23, 2014
1 parent 0c91f18 commit fcbd5bc
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 115 deletions.
79 changes: 40 additions & 39 deletions config/config.html
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
<div id="template" class="well">
<h2>Template Config Page</h2>
<button ng-click="save()" class="btn btn-primary">Save</button>
<br/>
<br/>
<p class="help-text">
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
</p>
<h3>Environment</h3>
<div class="row-fluid">
<div class="span12">
<textarea ui-refresh="selectedTab" ng-model="config.environment"></textarea>
</div>
<h2>Template Config Page</h2>
<button ng-click="save()" class="btn btn-primary">Save</button><br/><br/>

<p class="help-text">
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
</p>

<h3>Environment</h3>
<div class="row-fluid">
<div class="span12">
<textarea ui-refresh="selectedTab" ng-model="config.environment"></textarea>
</div>
<br/>
<h3>Prepare</h3>
<div class="row-fluid">
<div class="span12">
<textarea ui-refresh="selectedTab" ng-model="config.prepare"></textarea>
</div>
</div><br/>

<h3>Prepare</h3>
<div class="row-fluid">
<div class="span12">
<textarea ui-refresh="selectedTab" ng-model="config.prepare"></textarea>
</div>
<br/>
<h3>Test</h3>
<div class="row-fluid">
<div class="span12">
<textarea ui-refresh="selectedTab" ng-model="config.test"></textarea>
</div>
</div><br/>

<h3>Test</h3>
<div class="row-fluid">
<div class="span12">
<textarea ui-refresh="selectedTab" ng-model="config.test"></textarea>
</div>
<br/>
<h3>Deploy</h3>
<div class="row-fluid">
<div class="span12">
<textarea ui-refresh="selectedTab" ng-model="config.deploy"></textarea>
</div>
</div><br/>

<h3>Deploy</h3>
<div class="row-fluid">
<div class="span12">
<textarea ui-refresh="selectedTab" ng-model="config.deploy"></textarea>
</div>
<br/>
<h3>Cleanup</h3>
<div class="row-fluid cleanup">
<div class="span12">
<textarea ui-refresh="selectedTab" ng-model="config.cleanup"></textarea>
</div>
</div><br/>

<h3>Cleanup</h3>
<div class="row-fluid cleanup">
<div class="span12">
<textarea ui-refresh="selectedTab" ng-model="config.cleanup"></textarea>
</div>
<button ng-click="save()" class="btn btn-primary">Save</button>
</div>
</div>

<button ng-click="save()" class="btn btn-primary">Save</button>
</div>
23 changes: 13 additions & 10 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand All @@ -21,5 +25,4 @@ app.controller('TemplateCtrl', ['$scope', function ($scope) {
$scope.saving = false;
});
};

}]);
}]);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"webapp": "webapp.js",
"icon": "icon.png",
"config": {
"controller": "TemplateCtrl"
"controller": "TemplateController"
}
},
"devDependencies": {
Expand Down
53 changes: 28 additions & 25 deletions test/worker_test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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"');
Expand All @@ -62,5 +66,4 @@ describe("template worker test example", function() {
//test returns a function
expect(typeof setup.test).to.equal('function');
});

});
68 changes: 33 additions & 35 deletions webapp.js
Original file line number Diff line number Diff line change
@@ -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`' }
}


};
},
// 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) {
}
};
13 changes: 8 additions & 5 deletions worker.js
Original file line number Diff line number Diff line change
@@ -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);
};

Expand All @@ -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: {},
Expand Down Expand Up @@ -54,14 +57,14 @@ module.exports = {
// positives.
return done(null, false);
}

doThings(function (err) {
done(err, true);
});
});
},
deploy: 'echo "' + config.deploy + '"',
cleanup: 'echo "' + config.cleanup + '"'

});
},
// this is only used if there is _no_ plugin configuration for a
Expand All @@ -70,4 +73,4 @@ module.exports = {
filename: 'package.json',
exists: true
}
};
};

0 comments on commit fcbd5bc

Please sign in to comment.