navy
Version:
Quick and powerful development environments using Docker and Docker Compose
78 lines (76 loc) • 3.14 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _chai = require("chai");
var _sinon = _interopRequireDefault(require("sinon"));
var _proxyquire = _interopRequireDefault(require("proxyquire"));
/* eslint-env mocha */
describe('cli/util/reconfigure', function () {
let sandbox;
let getLaunchedNaviesStub;
let startDriverLoggingStub;
let stopDriverLoggingStub;
let reconfigureAllNavies;
beforeEach(function () {
sandbox = _sinon.default.createSandbox();
getLaunchedNaviesStub = sandbox.stub();
startDriverLoggingStub = sandbox.stub();
stopDriverLoggingStub = sandbox.stub();
reconfigureAllNavies = _proxyquire.default.noCallThru()('../reconfigure', {
'../../': {
getLaunchedNavies: getLaunchedNaviesStub
},
'../../driver-logging': {
startDriverLogging: startDriverLoggingStub,
stopDriverLogging: stopDriverLoggingStub
}
}).reconfigureAllNavies;
});
afterEach(function () {
sandbox.restore();
});
describe('reconfigureAllNavies', function () {
it('should be a no-op when there are no launched navies', async function () {
getLaunchedNaviesStub.resolves([]);
await reconfigureAllNavies();
(0, _chai.expect)(getLaunchedNaviesStub.calledOnce).to.equal(true);
(0, _chai.expect)(startDriverLoggingStub.called).to.equal(false);
(0, _chai.expect)(stopDriverLoggingStub.called).to.equal(false);
});
it('should reconfigure each launched navy in turn with bracketed driver logging', async function () {
const navyA = {
name: 'envA',
reconfigure: sandbox.stub().resolves()
};
const navyB = {
name: 'envB',
reconfigure: sandbox.stub().resolves()
};
getLaunchedNaviesStub.resolves([navyA, navyB]);
await reconfigureAllNavies();
(0, _chai.expect)(navyA.reconfigure.calledOnce).to.equal(true);
(0, _chai.expect)(navyB.reconfigure.calledOnce).to.equal(true);
(0, _chai.expect)(startDriverLoggingStub.callCount).to.equal(2);
(0, _chai.expect)(stopDriverLoggingStub.callCount).to.equal(2);
});
it('should pass a message that includes the navy name to startDriverLogging', async function () {
const navy = {
name: 'envA',
reconfigure: sandbox.stub().resolves()
};
getLaunchedNaviesStub.resolves([navy]);
await reconfigureAllNavies();
(0, _chai.expect)(startDriverLoggingStub.firstCall.args[0]).to.contain('envA');
(0, _chai.expect)(startDriverLoggingStub.firstCall.args[0]).to.contain('Reconfiguring');
});
it('should call startDriverLogging before each reconfigure and stopDriverLogging after', async function () {
const navy = {
name: 'envA',
reconfigure: sandbox.stub().resolves()
};
getLaunchedNaviesStub.resolves([navy]);
await reconfigureAllNavies();
(0, _chai.expect)(startDriverLoggingStub.calledBefore(navy.reconfigure)).to.equal(true);
(0, _chai.expect)(navy.reconfigure.calledBefore(stopDriverLoggingStub)).to.equal(true);
});
});
});