mockTemplate.reset(); withPipe.close(done); });
mockTemplate.reset(); withFile.close(done); });
mockTemplate.reset(); serverCustomOptions.close(done); });
it('isSupported fn', function () { const shell = sinon.stub(execa, 'shellSync'); const inst = new Nginx({}, {}, {}, '/some/dir'); expect(inst.isSupported()).to.be.true; expect(shell.calledOnce).to.be.true; shell.reset(); shell.throws(new Error()); expect(inst.isSupported()).to.be.false; expect(shell.calledOnce).to.be.true; });
it('configureSubcommands works', function () { const yargsStub = {}; yargsStub.command = sinon.stub().returns(yargsStub); const extensions = [{extensionA: true}]; const ConfigCommand = require(modulePath); const runStub = sinon.stub(ConfigCommand, '_run'); ConfigCommand.configureSubcommands('config', yargsStub, extensions); expect(yargsStub.command.calledTwice).to.be.true; const command1 = yargsStub.command.args[0][0]; expect(command1.command).to.equal('get <key>'); expect(command1.handler).to.be.a('function'); command1.handler({args: true}); expect(runStub.calledOnce).to.be.true; expect(runStub.calledWithExactly('config get', {args: true}, extensions)).to.be.true; runStub.reset(); const command2 = yargsStub.command.args[1][0]; expect(command2.command).to.equal('set <key> <value>'); expect(command2.handler).to.be.a('function'); command2.handler({args: true}); expect(runStub.calledOnce).to.be.true; expect(runStub.calledWithExactly('config set', {args: true}, extensions)).to.be.true; });
beforeEach(() => { clientOptions = { hostname: "catwatch.opensource.zalan.do" }; requestStub.reset(); requestStub.returns(emptySuccessResponse); });
describe('restartNginx', function () { const sudo = sinon.stub(); const inst = new Nginx({sudo}, {}, {}, '/some/dir'); afterEach(() => sudo.reset()); it('Soft reloads nginx', function () { sudo.resolves(); return inst.restartNginx().then(() => { expect(sudo.calledOnce).to.be.true; expect(sudo.calledWithExactly('nginx -s reload')).to.be.true; }); }); it('throws an error when nginx does', function () { const err = new Error('ssl error'); sudo.rejects(err); return inst.restartNginx().then(() => { expect(false, 'An error should have been thrown').to.be.true; }).catch((error) => { expect(sudo.calledOnce).to.be.true; expect(sudo.calledWithExactly('nginx -s reload')).to.be.true; expect(error).to.be.an.instanceof(errors.CliError); expect(error.message).to.equal('Failed to restart Nginx.'); }); }); });
function reset() { exists.resetHistory(); config.get.reset(); }
afterEach(() => { portPollingStub.reset(); });