mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-01-10 23:35:09 +00:00
add trigger after tests
This commit is contained in:
parent
85f4fab192
commit
27d8e73b26
19
test/distributor/helpers.js
Normal file
19
test/distributor/helpers.js
Normal file
@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
var Node = require('../../lib/node').Node,
|
||||
EventEmitter = require('events').EventEmitter;
|
||||
|
||||
|
||||
exports.createNodeMock = function(executorRun) {
|
||||
return function(params) {
|
||||
var node = new Node(params);
|
||||
node._createExecutor = function(project) {
|
||||
var executor = new EventEmitter();
|
||||
executor.project = project;
|
||||
executor.run = executorRun;
|
||||
return executor;
|
||||
};
|
||||
return node;
|
||||
};
|
||||
};
|
||||
|
@ -1,3 +1,4 @@
|
||||
'use strict';
|
||||
|
||||
require('./main.js');
|
||||
require('./triggerAfter.js');
|
||||
|
@ -1,28 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
var Distributor = require('../../lib/distributor').Distributor,
|
||||
Node = require('../../lib/node').Node,
|
||||
expect = require('expect.js'),
|
||||
EventEmitter = require('events').EventEmitter,
|
||||
sinon = require('sinon')
|
||||
sinon = require('sinon'),
|
||||
createNodeMock = require('./helpers').createNodeMock;
|
||||
|
||||
|
||||
describe('Distributor', function() {
|
||||
describe('Distributor main', function() {
|
||||
var distributor,
|
||||
projects = [{name: 'project1'}];
|
||||
|
||||
var createNodeMock = function(executorRun) {
|
||||
return function(params) {
|
||||
var node = new Node(params);
|
||||
node._createExecutor = function() {
|
||||
var executor = new EventEmitter();
|
||||
executor.run = executorRun;
|
||||
return executor;
|
||||
};
|
||||
return node;
|
||||
};
|
||||
};
|
||||
|
||||
var expectUpdateBuild = function(distributor, build, number, conditionsHash) {
|
||||
var conditions = conditionsHash[number];
|
||||
expect(distributor.queue).length(conditions.queue.length);
|
||||
@ -34,11 +21,8 @@ describe('Distributor', function() {
|
||||
|
||||
describe('with success project', function() {
|
||||
before(function() {
|
||||
var executorRun = function(params, callback) {
|
||||
setTimeout(callback, 1);
|
||||
};
|
||||
sinon.stub(Distributor.prototype, '_createNode', createNodeMock(
|
||||
executorRun
|
||||
sinon.stub().callsArgAsync(1)
|
||||
));
|
||||
});
|
||||
|
||||
@ -97,13 +81,8 @@ describe('Distributor', function() {
|
||||
|
||||
describe('with fail project', function() {
|
||||
before(function() {
|
||||
var executorRun = function(params, callback) {
|
||||
setTimeout(function() {
|
||||
callback(new Error('Some error'));
|
||||
}, 1);
|
||||
};
|
||||
sinon.stub(Distributor.prototype, '_createNode', createNodeMock(
|
||||
executorRun
|
||||
sinon.stub().callsArgWithAsync(1, new Error('Some error'))
|
||||
));
|
||||
});
|
||||
|
||||
|
174
test/distributor/triggerAfter.js
Normal file
174
test/distributor/triggerAfter.js
Normal file
@ -0,0 +1,174 @@
|
||||
'use strict';
|
||||
|
||||
var Distributor = require('../../lib/distributor').Distributor,
|
||||
expect = require('expect.js'),
|
||||
sinon = require('sinon'),
|
||||
createNodeMock = require('./helpers').createNodeMock;
|
||||
|
||||
|
||||
describe('Distributor trigger after', function() {
|
||||
var distributor, executorRunSpy, projects;
|
||||
|
||||
var nodes = [{type: 'local', maxExecutorsCount: 1}];
|
||||
|
||||
describe('done when project is done', function() {
|
||||
before(function() {
|
||||
projects = [{
|
||||
name: 'project1',
|
||||
trigger: {
|
||||
after: [{status: 'done', project: 'project2'}]
|
||||
}
|
||||
}, {
|
||||
name: 'project2'
|
||||
}];
|
||||
executorRunSpy = sinon.stub().callsArgAsync(1);
|
||||
sinon.stub(Distributor.prototype, '_createNode', createNodeMock(
|
||||
executorRunSpy
|
||||
));
|
||||
});
|
||||
|
||||
it('distributor should be created without errors', function() {
|
||||
distributor = new Distributor({projects: projects, nodes: nodes});
|
||||
});
|
||||
|
||||
it('should run without errors', function(done) {
|
||||
distributor.run({projectName: 'project1'}, function(err) {
|
||||
expect(err).not.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should run project1 at first call', function() {
|
||||
expect(executorRunSpy.getCall(0).thisValue.project).eql(projects[0]);
|
||||
});
|
||||
|
||||
it('should run project2 at second call', function() {
|
||||
expect(executorRunSpy.getCall(1).thisValue.project).eql(projects[1]);
|
||||
});
|
||||
|
||||
it('should run totally 2 times', function() {
|
||||
expect(executorRunSpy.callCount).equal(2);
|
||||
});
|
||||
|
||||
after(function() {
|
||||
Distributor.prototype._createNode.restore();
|
||||
});
|
||||
});
|
||||
|
||||
describe('done when project is error', function() {
|
||||
before(function() {
|
||||
executorRunSpy = sinon.stub().callsArgWithAsync(1, new Error(
|
||||
'Some error'
|
||||
));
|
||||
sinon.stub(Distributor.prototype, '_createNode', createNodeMock(
|
||||
executorRunSpy
|
||||
));
|
||||
});
|
||||
|
||||
it('distributor should be created without errors', function() {
|
||||
distributor = new Distributor({projects: projects, nodes: nodes});
|
||||
});
|
||||
|
||||
it('should run without errors', function(done) {
|
||||
distributor.run({projectName: 'project1'}, function(err) {
|
||||
expect(err).not.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should run project1 at first call', function() {
|
||||
expect(executorRunSpy.getCall(0).thisValue.project).eql(projects[0]);
|
||||
});
|
||||
|
||||
it('should run totally 1 time', function() {
|
||||
expect(executorRunSpy.callCount).equal(1);
|
||||
});
|
||||
|
||||
after(function() {
|
||||
Distributor.prototype._createNode.restore();
|
||||
});
|
||||
});
|
||||
|
||||
describe('status is not set when project is done', function() {
|
||||
before(function() {
|
||||
projects = [{
|
||||
name: 'project1',
|
||||
trigger: {
|
||||
after: [{project: 'project2'}]
|
||||
}
|
||||
}, {
|
||||
name: 'project2'
|
||||
}];
|
||||
executorRunSpy = sinon.stub().callsArgAsync(1);
|
||||
sinon.stub(Distributor.prototype, '_createNode', createNodeMock(
|
||||
executorRunSpy
|
||||
));
|
||||
});
|
||||
|
||||
it('distributor should be created without errors', function() {
|
||||
distributor = new Distributor({projects: projects, nodes: nodes});
|
||||
});
|
||||
|
||||
it('should run without errors', function(done) {
|
||||
distributor.run({projectName: 'project1'}, function(err) {
|
||||
expect(err).not.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should run project1 at first call', function() {
|
||||
expect(executorRunSpy.getCall(0).thisValue.project).eql(projects[0]);
|
||||
});
|
||||
|
||||
it('should run project2 at second call', function() {
|
||||
expect(executorRunSpy.getCall(1).thisValue.project).eql(projects[1]);
|
||||
});
|
||||
|
||||
it('should run totally 2 times', function() {
|
||||
expect(executorRunSpy.callCount).equal(2);
|
||||
});
|
||||
|
||||
after(function() {
|
||||
Distributor.prototype._createNode.restore();
|
||||
});
|
||||
});
|
||||
|
||||
describe('status is not set when project is error', function() {
|
||||
before(function() {
|
||||
executorRunSpy = sinon.stub().callsArgWithAsync(1, new Error(
|
||||
'Some error'
|
||||
));
|
||||
sinon.stub(Distributor.prototype, '_createNode', createNodeMock(
|
||||
executorRunSpy
|
||||
));
|
||||
});
|
||||
|
||||
it('distributor should be created without errors', function() {
|
||||
distributor = new Distributor({projects: projects, nodes: nodes});
|
||||
});
|
||||
|
||||
it('should run without errors', function(done) {
|
||||
distributor.run({projectName: 'project1'}, function(err) {
|
||||
expect(err).not.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should run project1 at first call', function() {
|
||||
expect(executorRunSpy.getCall(0).thisValue.project).eql(projects[0]);
|
||||
});
|
||||
|
||||
it('should run project2 at second call', function() {
|
||||
expect(executorRunSpy.getCall(1).thisValue.project).eql(projects[1]);
|
||||
});
|
||||
|
||||
it('should run totally 2 times', function() {
|
||||
expect(executorRunSpy.callCount).equal(2);
|
||||
});
|
||||
|
||||
after(function() {
|
||||
Distributor.prototype._createNode.restore();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user