UNPKG

navy

Version:

Quick and powerful development environments using Docker and Docker Compose

103 lines (101 loc) 3.77 kB
"use strict"; 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/doctor/invalid-compose-config', function () { let sandbox; let getLaunchedNaviesStub; let startStub; let fixStub; let catchInvariantStub; let invalidComposeConfig; beforeEach(function () { sandbox = _sinon.default.createSandbox(); getLaunchedNaviesStub = sandbox.stub().resolves([]); startStub = sandbox.stub(); fixStub = sandbox.stub().callsFake(async (msg, name, callback) => callback()); catchInvariantStub = sandbox.stub().callsFake(async (code, fn, catchCallback) => { try { await fn(); } catch (err) { if (err.name === 'Invariant Violation' && err.message.indexOf(code) === 0) { await catchCallback(); } } }); invalidComposeConfig = _proxyquire.default.noCallThru()('../invalid-compose-config', { '../../': { getLaunchedNavies: getLaunchedNaviesStub }, './util': { start: startStub, fix: fixStub, catchInvariant: catchInvariantStub } }); }); afterEach(function () { sandbox.restore(); }); describe('default export', function () { it('should log a starting message', async function () { await invalidComposeConfig(); (0, _chai.expect)(startStub.calledOnce).to.equal(true); (0, _chai.expect)(startStub.firstCall.args[0]).to.contain('compose'); }); it('should do nothing further when there are no launched navies', async function () { getLaunchedNaviesStub.resolves([]); await invalidComposeConfig(); (0, _chai.expect)(catchInvariantStub.called).to.equal(false); (0, _chai.expect)(fixStub.called).to.equal(false); }); it('should call safeGetDriver().getConfig() for each navy', async function () { const driver = { getConfig: sandbox.stub().resolves({}) }; const navy = { name: 'env-1', safeGetDriver: sandbox.stub().resolves(driver), delete: sandbox.stub().resolves() }; getLaunchedNaviesStub.resolves([navy]); await invalidComposeConfig(); (0, _chai.expect)(navy.safeGetDriver.calledOnce).to.equal(true); (0, _chai.expect)(driver.getConfig.calledOnce).to.equal(true); }); it('should remove a navy whose driver throws NO_DOCKER_COMPOSE_FILE invariant', async function () { const err = new Error('NO_DOCKER_COMPOSE_FILE: not found'); err.name = 'Invariant Violation'; const driver = { getConfig: sandbox.stub().rejects(err) }; const navy = { name: 'env-1', safeGetDriver: sandbox.stub().resolves(driver), delete: sandbox.stub().resolves() }; getLaunchedNaviesStub.resolves([navy]); await invalidComposeConfig(); (0, _chai.expect)(fixStub.calledOnce).to.equal(true); (0, _chai.expect)(navy.delete.calledOnce).to.equal(true); }); it('should not call delete when the driver throws a different invariant', async function () { const err = new Error('SOMETHING_ELSE: nope'); err.name = 'Invariant Violation'; const driver = { getConfig: sandbox.stub().rejects(err) }; const navy = { name: 'env-1', safeGetDriver: sandbox.stub().resolves(driver), delete: sandbox.stub().resolves() }; getLaunchedNaviesStub.resolves([navy]); await invalidComposeConfig(); (0, _chai.expect)(fixStub.called).to.equal(false); (0, _chai.expect)(navy.delete.called).to.equal(false); }); }); });