Skip to content

Commit 02f9b21

Browse files
committed
test(MongoInstance): change some "toEqual" strings to snapshots
1 parent 01591eb commit 02f9b21

File tree

2 files changed

+45
-31
lines changed

2 files changed

+45
-31
lines changed

packages/mongodb-memory-server-core/src/util/__tests__/MongoInstance.test.ts

+9-31
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ describe('MongodbInstance', () => {
339339
const event = events.get(MongoInstanceEvents.instanceError);
340340
expect(event).toBeInstanceOf(StdoutInstanceError);
341341
assertIsError(event); // has to be used, because there is not typeguard from "expect(variable).toBeInstanceOf"
342-
expect(event.message).toEqual('Port "1001" already in use');
342+
expect(event.message).toMatchSnapshot();
343343
});
344344

345345
it('should emit "instanceError" when curl-open-ssl-3 is not found', () => {
@@ -355,10 +355,7 @@ describe('MongodbInstance', () => {
355355
const event = events.get(MongoInstanceEvents.instanceError);
356356
expect(event).toBeInstanceOf(StdoutInstanceError);
357357
assertIsError(event); // has to be used, because there is not typeguard from "expect(variable).toBeInstanceOf"
358-
expect(event.message).toEqual(
359-
'libcurl3 is not available on your system. Mongod requires it and cannot be started without it.\n' +
360-
'You should manually install libcurl3 or try to use an newer version of MongoDB'
361-
);
358+
expect(event.message).toMatchSnapshot();
362359
});
363360

364361
it('should emit "instanceError" when curl-open-ssl-4 is not found', () => {
@@ -374,10 +371,7 @@ describe('MongodbInstance', () => {
374371
const event = events.get(MongoInstanceEvents.instanceError);
375372
expect(event).toBeInstanceOf(StdoutInstanceError);
376373
assertIsError(event); // has to be used, because there is not typeguard from "expect(variable).toBeInstanceOf"
377-
expect(event.message).toEqual(
378-
'libcurl4 is not available on your system. Mongod requires it and cannot be started without it.\n' +
379-
'You need to manually install libcurl4'
380-
);
374+
expect(event.message).toMatchSnapshot();
381375
});
382376

383377
it('should emit "instancePrimary" when "transition to primary complete" is found', () => {
@@ -420,9 +414,7 @@ describe('MongodbInstance', () => {
420414
const event = events.get(MongoInstanceEvents.instanceError);
421415
expect(event).toBeInstanceOf(StdoutInstanceError);
422416
assertIsError(event); // has to be used, because there is not typeguard from "expect(variable).toBeInstanceOf"
423-
expect(event.message).toEqual(
424-
'Instance failed to start because a library is missing or cannot be opened: "libcrypto.so.10"'
425-
);
417+
expect(event.message).toMatchSnapshot();
426418
});
427419

428420
describe('should emit "instanceError" when "excepetion in initAndListen" is thrown', () => {
@@ -440,10 +432,7 @@ describe('MongodbInstance', () => {
440432
const event = events.get(MongoInstanceEvents.instanceError);
441433
expect(event).toBeInstanceOf(StdoutInstanceError);
442434
assertIsError(event); // has to be used, because there is not typeguard from "expect(variable).toBeInstanceOf"
443-
expect(event.message).toEqual(
444-
'Instance Failed to start with "DBPathInUse". Original Error:\n' +
445-
'Unable to create/open the lock file: /dev/null/mongod.lock (Not a directory). Ensure the user executing mongod is the owner of the lock file and has the appropriate permissions. Also make sure that another mongod instance is not already running on the /dev/null directory'
446-
);
435+
expect(event.message).toMatchSnapshot();
447436
});
448437

449438
it('DbPathInUse (already running)', () => {
@@ -460,10 +449,7 @@ describe('MongodbInstance', () => {
460449
const event = events.get(MongoInstanceEvents.instanceError);
461450
expect(event).toBeInstanceOf(StdoutInstanceError);
462451
assertIsError(event); // has to be used, because there is not typeguard from "expect(variable).toBeInstanceOf"
463-
expect(event.message).toEqual(
464-
'Instance Failed to start with "DBPathInUse". Original Error:\n' +
465-
'Unable to lock the lock file: /tmp/hellodb/mongod.lock (Resource temporarily unavailable). Another mongod instance is already running on the /tmp/hellodb directory'
466-
);
452+
expect(event.message).toMatchSnapshot();
467453
});
468454

469455
it('Location28596', () => {
@@ -480,10 +466,7 @@ describe('MongodbInstance', () => {
480466
const event = events.get(MongoInstanceEvents.instanceError);
481467
expect(event).toBeInstanceOf(StdoutInstanceError);
482468
assertIsError(event); // has to be used, because there is not typeguard from "expect(variable).toBeInstanceOf"
483-
expect(event.message).toEqual(
484-
'Instance Failed to start with "Location28596". Original Error:\n' +
485-
'Unable to determine status of lock file in the data directory /root: boost::filesystem::status: Permission denied: "/root/mongod.lock"'
486-
);
469+
expect(event.message).toMatchSnapshot();
487470
});
488471

489472
it('NonExistentPath', () => {
@@ -500,10 +483,7 @@ describe('MongodbInstance', () => {
500483
const event = events.get(MongoInstanceEvents.instanceError);
501484
expect(event).toBeInstanceOf(StdoutInstanceError);
502485
assertIsError(event); // has to be used, because there is not typeguard from "expect(variable).toBeInstanceOf"
503-
expect(event.message).toEqual(
504-
'Instance Failed to start with "NonExistentPath". Original Error:\n' +
505-
"Data directory /tmp/hello not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file."
506-
);
486+
expect(event.message).toMatchSnapshot();
507487
});
508488
});
509489
});
@@ -522,9 +502,7 @@ describe('MongodbInstance', () => {
522502
const event = events.get(MongoInstanceEvents.instanceError);
523503
expect(event).toBeInstanceOf(StdoutInstanceError);
524504
assertIsError(event); // has to be used, because there is not typeguard from "expect(variable).toBeInstanceOf"
525-
expect(event.message).toEqual(
526-
'Instance failed to start because a library is missing or cannot be opened: "libcrypto.so.1.1"'
527-
);
505+
expect(event.message).toMatchSnapshot();
528506
});
529507
});
530508
});

packages/mongodb-memory-server-core/src/util/__tests__/__snapshots__/MongoInstance.test.ts.snap

+36
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,39 @@ exports[`MongodbInstance "_launchMongod" should throw an error if "mongodProcess
55
exports[`MongodbInstance prepareCommandArgs should throw an error if no dbpath is provided 1`] = `"\\"instanceOpts.dbPath\\" is required to be set!"`;
66

77
exports[`MongodbInstance prepareCommandArgs should throw an error if no port is provided 1`] = `"\\"instanceOpts.port\\" is required to be set!"`;
8+
9+
exports[`MongodbInstance test events checkErrorInLine() should emit "instanceError" when shared libraries fail to load 1`] = `"Instance failed to start because a library is missing or cannot be opened: \\"libcrypto.so.1.1\\""`;
10+
11+
exports[`MongodbInstance test events stdoutHandler() should emit "instanceError" when "excepetion in initAndListen" is thrown DbPathInUse (Not a directory) 1`] = `
12+
"Instance Failed to start with \\"DBPathInUse\\". Original Error:
13+
Unable to create/open the lock file: /dev/null/mongod.lock (Not a directory). Ensure the user executing mongod is the owner of the lock file and has the appropriate permissions. Also make sure that another mongod instance is not already running on the /dev/null directory"
14+
`;
15+
16+
exports[`MongodbInstance test events stdoutHandler() should emit "instanceError" when "excepetion in initAndListen" is thrown DbPathInUse (already running) 1`] = `
17+
"Instance Failed to start with \\"DBPathInUse\\". Original Error:
18+
Unable to lock the lock file: /tmp/hellodb/mongod.lock (Resource temporarily unavailable). Another mongod instance is already running on the /tmp/hellodb directory"
19+
`;
20+
21+
exports[`MongodbInstance test events stdoutHandler() should emit "instanceError" when "excepetion in initAndListen" is thrown Location28596 1`] = `
22+
"Instance Failed to start with \\"Location28596\\". Original Error:
23+
Unable to determine status of lock file in the data directory /root: boost::filesystem::status: Permission denied: \\"/root/mongod.lock\\""
24+
`;
25+
26+
exports[`MongodbInstance test events stdoutHandler() should emit "instanceError" when "excepetion in initAndListen" is thrown NonExistentPath 1`] = `
27+
"Instance Failed to start with \\"NonExistentPath\\". Original Error:
28+
Data directory /tmp/hello not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file."
29+
`;
30+
31+
exports[`MongodbInstance test events stdoutHandler() should emit "instanceError" when curl-open-ssl-3 is not found 1`] = `
32+
"libcurl3 is not available on your system. Mongod requires it and cannot be started without it.
33+
You should manually install libcurl3 or try to use an newer version of MongoDB"
34+
`;
35+
36+
exports[`MongodbInstance test events stdoutHandler() should emit "instanceError" when curl-open-ssl-4 is not found 1`] = `
37+
"libcurl4 is not available on your system. Mongod requires it and cannot be started without it.
38+
You need to manually install libcurl4"
39+
`;
40+
41+
exports[`MongodbInstance test events stdoutHandler() should emit "instanceError" when library is missing 1`] = `"Instance failed to start because a library is missing or cannot be opened: \\"libcrypto.so.10\\""`;
42+
43+
exports[`MongodbInstance test events stdoutHandler() should emit "instanceError" when port is already in use 1`] = `"Port \\"1001\\" already in use"`;

0 commit comments

Comments
 (0)