navy
Version:
Quick and powerful development environments using Docker and Docker Compose
90 lines (88 loc) • 3.24 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/lan-ip', function () {
let sandbox;
let getLANIPStub;
let setConfigStub;
let getConfigStub;
let reconfigureAllNaviesStub;
let consoleLogStub;
let lanIpCli;
beforeEach(function () {
sandbox = _sinon.default.createSandbox();
getLANIPStub = sandbox.stub();
setConfigStub = sandbox.stub().resolves();
getConfigStub = sandbox.stub();
reconfigureAllNaviesStub = sandbox.stub().resolves();
consoleLogStub = sandbox.stub(console, 'log');
lanIpCli = _proxyquire.default.noCallThru()('../lan-ip', {
'../util/get-lan-ip': {
getLANIP: getLANIPStub
},
'../config': {
setConfig: setConfigStub,
getConfig: getConfigStub
},
'./util/reconfigure': {
reconfigureAllNavies: reconfigureAllNaviesStub
}
});
});
afterEach(function () {
sandbox.restore();
});
describe('default export', function () {
it('should look up the LAN IP via getLANIP', async function () {
getLANIPStub.resolves('10.0.0.5');
getConfigStub.returns({
defaultNavy: 'dev'
});
await lanIpCli();
(0, _chai.expect)(getLANIPStub.calledOnce).to.equal(true);
});
it('should write a config that merges existing config with the new externalIP', async function () {
getLANIPStub.resolves('10.0.0.5');
getConfigStub.returns({
defaultNavy: 'dev',
tlsRootCaDir: '/ca'
});
await lanIpCli();
(0, _chai.expect)(setConfigStub.calledOnce).to.equal(true);
(0, _chai.expect)(setConfigStub.firstCall.args[0]).to.eql({
defaultNavy: 'dev',
tlsRootCaDir: '/ca',
externalIP: '10.0.0.5'
});
});
it('should override an existing externalIP in config with the LAN IP', async function () {
getLANIPStub.resolves('10.0.0.5');
getConfigStub.returns({
externalIP: 'old.host',
defaultNavy: 'dev'
});
await lanIpCli();
(0, _chai.expect)(setConfigStub.firstCall.args[0].externalIP).to.equal('10.0.0.5');
});
it('should reconfigure all navies after writing the new config', async function () {
getLANIPStub.resolves('10.0.0.5');
getConfigStub.returns({});
await lanIpCli();
(0, _chai.expect)(reconfigureAllNaviesStub.calledOnce).to.equal(true);
(0, _chai.expect)(setConfigStub.calledBefore(reconfigureAllNaviesStub)).to.equal(true);
});
it('should log a confirmation including the LAN IP', async function () {
getLANIPStub.resolves('10.0.0.5');
getConfigStub.returns({});
await lanIpCli();
const messages = consoleLogStub.getCalls().map(c => c.args[0] || '');
const hasLanIp = messages.some(m => typeof m === 'string' && m.includes('10.0.0.5'));
(0, _chai.expect)(hasLanIp).to.equal(true);
const hasLabel = messages.some(m => typeof m === 'string' && m.includes('LAN IP'));
(0, _chai.expect)(hasLabel).to.equal(true);
});
});
});