Skip to content

Commit

Permalink
tests: add end to end deletion test
Browse files Browse the repository at this point in the history
  • Loading branch information
gagik committed Feb 10, 2025
1 parent cc82c07 commit 6d8a794
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions packages/e2e-tests/test/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,58 @@ describe('e2e', function () {
});
});

describe('with custom log retention max file count', function () {
const customLogDir = useTmpdir();

it('should delete files once it is above the max file count limit', async function () {
const globalConfig = path.join(homedir, 'globalconfig.conf');
await fs.writeFile(
globalConfig,
`mongosh:\n logLocation: ${JSON.stringify(
customLogDir.path
)}\n logMaxFileCount: 4`
);
const paths: string[] = [];
const offset = Math.floor(Date.now() / 1000);

// Create 10 log files
for (let i = 9; i >= 0; i--) {
const filename = path.join(
customLogDir.path,
ObjectId.createFromTime(offset - i).toHexString() + '_log'
);
await fs.writeFile(filename, '');
paths.push(filename);
}

// All 10 existing log files exist.
expect(await getFilesState(paths)).to.equal('1111111111');
shell = this.startTestShell({
args: ['--nodb'],
env: {
...env,
MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT: '',
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig,
},
forceTerminal: true,
});

await shell.waitForPrompt();

// Add the newly created log to the file list.
paths.push(
path.join(customLogDir.path, `${shell.logId as string}_log`)
);

expect(
await shell.executeLine('config.get("logMaxFileCount")')
).contains('4');

// Expect 7 files to be deleted and 4 to remain (including the new log file)
expect(await getFilesState(paths)).to.equal('00000001111');
});
});

it('creates a log file that keeps track of session events', async function () {
expect(await shell.executeLine('print(123 + 456)')).to.include('579');
const log = await readLogFile();
Expand Down

0 comments on commit 6d8a794

Please sign in to comment.