Skip to content

Commit 11b14ac

Browse files
committed
test: add test for log manager throwing error
1 parent a6bc600 commit 11b14ac

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

packages/cli-repl/src/cli-repl.spec.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ import type { DevtoolsConnectOptions } from '@mongosh/service-provider-node-driv
3333
import type { AddressInfo } from 'net';
3434
import sinon from 'sinon';
3535
import type { CliUserConfig } from '@mongosh/types';
36-
import { MongoLogWriter } from 'mongodb-log-writer';
36+
import { MongoLogWriter, MongoLogManager } from 'mongodb-log-writer';
3737
const { EJSON } = bson;
3838

3939
const delay = promisify(setTimeout);
4040

41-
describe('CliRepl', function () {
41+
describe.only('CliRepl', function () {
4242
let cliReplOptions: CliReplOptions;
4343
let cliRepl: CliRepl & {
4444
start(
@@ -478,12 +478,14 @@ describe('CliRepl', function () {
478478
cliRepl = new CliRepl(cliReplOptions);
479479
await cliRepl.start('', {});
480480
await fs.stat(newerlogfile);
481-
try {
482-
await fs.stat(oldlogfile);
483-
expect.fail('missed exception');
484-
} catch (err: any) {
485-
expect(err.code).to.equal('ENOENT');
486-
}
481+
await eventually(async () => {
482+
try {
483+
await fs.stat(oldlogfile);
484+
expect.fail('missed exception');
485+
} catch (err: any) {
486+
expect(err.code).to.equal('ENOENT');
487+
}
488+
});
487489
});
488490

489491
it('verifies the Node.js version', async function () {
@@ -1382,6 +1384,7 @@ describe('CliRepl', function () {
13821384
srv.close();
13831385
await once(srv, 'close');
13841386
setTelemetryDelay(0);
1387+
sinon.restore();
13851388
});
13861389

13871390
context('logging configuration', function () {
@@ -1409,6 +1412,20 @@ describe('CliRepl', function () {
14091412

14101413
expect(cliRepl.logWriter).is.undefined;
14111414
});
1415+
1416+
it('logs cleanup errors', async function () {
1417+
sinon
1418+
.stub(MongoLogManager.prototype, 'cleanupOldLogFiles')
1419+
.rejects(new Error('Method not implemented'));
1420+
await cliRepl.start(await testServer.connectionString(), {});
1421+
expect(
1422+
(await log()).filter(
1423+
(entry) =>
1424+
entry.ctx === 'log' &&
1425+
entry.msg === 'Error: Method not implemented'
1426+
)
1427+
).to.have.lengthOf(1);
1428+
});
14121429
});
14131430

14141431
it('times out fast', async function () {

0 commit comments

Comments
 (0)