From 83564f70918e6620dbb7259edc0972f0154d2937 Mon Sep 17 00:00:00 2001 From: oleg Date: Sun, 28 Jun 2015 10:47:06 +0300 Subject: [PATCH] add tests for rev catching --- .gitignore | 1 + lib/executor/local.js | 6 +- test/distributor/index.js | 1 + test/distributor/runSelfAfterCatchRev.js | 78 ++++++++++++++++++++++++ test/helpers.js | 2 - 5 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 test/distributor/runSelfAfterCatchRev.js diff --git a/.gitignore b/.gitignore index 749c290..c559d22 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ node_modules test/workspace +test/distributor/workspace static/css/**/*.css static/fonts static/js/libs diff --git a/lib/executor/local.js b/lib/executor/local.js index f5fa02e..a7de3cd 100644 --- a/lib/executor/local.js +++ b/lib/executor/local.js @@ -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); diff --git a/test/distributor/index.js b/test/distributor/index.js index f82ba52..577a879 100644 --- a/test/distributor/index.js +++ b/test/distributor/index.js @@ -3,3 +3,4 @@ require('./main.js'); require('./triggerAfter.js'); require('./blocking.js'); +require('./runSelfAfterCatchRev.js'); diff --git a/test/distributor/runSelfAfterCatchRev.js b/test/distributor/runSelfAfterCatchRev.js new file mode 100644 index 0000000..4cc291f --- /dev/null +++ b/test/distributor/runSelfAfterCatchRev.js @@ -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); + }); + + }); + +}); \ No newline at end of file diff --git a/test/helpers.js b/test/helpers.js index a8ce36a..2a44764 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -18,8 +18,6 @@ exports.removeDirIfExists = function(dir, done) { })); }; - - // revisions for the test mercurial repo exports.mercurialRevs = [{ id: 'da2762e71e87',