add tests for rev catching

This commit is contained in:
oleg 2015-06-28 10:47:06 +03:00
parent 9af5e9ade4
commit 83564f7091
5 changed files with 85 additions and 3 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
node_modules
test/workspace
test/distributor/workspace
static/css/**/*.css
static/fonts
static/js/libs

View File

@ -16,6 +16,10 @@ inherits(Executor, ParentExecutor);
exports.Executor = Executor;
Executor.prototype._createScm = function(params) {
return createScm(params);
};
Executor.prototype._getSources = function(params, callback) {
var self = this,
scm, isFirstRun, oldRev;
@ -35,7 +39,7 @@ Executor.prototype._getSources = function(params, callback) {
scmParams.repository = params.repository;
isFirstRun = true;
}
scm = createScm(scmParams);
scm = self._createScm(scmParams);
if (isFirstRun) {
this.pass(null);

View File

@ -3,3 +3,4 @@
require('./main.js');
require('./triggerAfter.js');
require('./blocking.js');
require('./runSelfAfterCatchRev.js');

View File

@ -0,0 +1,78 @@
var Distributor = require('../../lib/distributor').Distributor,
expect = require('expect.js'),
sinon = require('sinon'),
helpers = require('../helpers'),
path = require('path');
describe('Distributor run self after catch', function() {
var distributor, executorRunSpy, scmDataSpy;
var workspacePath = path.join(__dirname, 'workspace');
var nodes = [{type: 'local', maxExecutorsCount: 1}];
describe('works 3 when start from begin and catch every rev', function() {
before(function(done) {
helpers.removeDirIfExists(workspacePath, done);
distributor = new Distributor({
projects: [{
name: 'project1',
dir: __dirname,
scm: {
type: 'mercurial',
repository: path.join(__dirname, '..', 'repos', 'mercurial'),
rev: 'default'
},
steps: [
{type: 'shell', cmd: 'echo 1'}
],
catchRev: {comment: /.*/}
}],
nodes: nodes
});
var createExecutor = distributor.nodes[0]._createExecutor;
var executor;
distributor.nodes[0]._createExecutor = function() {
// don't try to do it at home, in general executor should be used
// only once. But here using it for the same project simplifies
// tests.
if (!executor) {
executor = createExecutor.apply(this, arguments);
executorRunSpy = sinon.spy(executor, 'run');
scmDataSpy = sinon.spy();
executor.on('scmData', scmDataSpy);
}
return executor;
};
});
it('should run without errors', function(done) {
distributor.run({projectName: 'project1'}, function(err) {
expect(err).not.ok();
done();
});
});
var itRunWithRev = function(callIndex, revIndex) {
it('should run with rev ' + revIndex, function() {
expect(executorRunSpy.getCall(callIndex).thisValue.project.name)
.equal('project1');
expect(scmDataSpy.getCall(callIndex).args[0].rev)
.eql(helpers.mercurialRevs[revIndex]);
});
};
itRunWithRev(0, 0);
itRunWithRev(1, 1);
itRunWithRev(2, 2);
it('should call run 3 times in total', function() {
expect(executorRunSpy.callCount).equal(3);
});
});
});

View File

@ -18,8 +18,6 @@ exports.removeDirIfExists = function(dir, done) {
}));
};
// revisions for the test mercurial repo
exports.mercurialRevs = [{
id: 'da2762e71e87',