Skip to content

Commit 0c7549e

Browse files
committed
Add tests
1 parent 0334266 commit 0c7549e

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

packages/mongodb-build-info/test/fixtures.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ export const DOCUMENT_DB_URIS = [
8080
'mongodb://x:y@elastic-docdb-123456789.eu-central-1.docdb-elastic.amazonaws.com:27017',
8181
];
8282

83+
export const FIRESTORE_URIS = [
84+
'mongodb://x:y@bbccdaf5-527a-4be5-9881-b7073e92002b.europe-north2.firestore.goog:443/test-db?loadBalanced=true&tls=true&authMechanism=SCRAM-SHA-256&retryWrites=false',
85+
];
86+
8387
export const COSMOSDB_BUILD_INFO = {
8488
_t: 'BuildInfoResponse',
8589
ok: 1,

packages/mongodb-build-info/test/index.spec.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect } from 'chai';
2+
23
import * as fixtures from './fixtures';
34
import {
45
isAtlas,
@@ -10,6 +11,7 @@ import {
1011
getBuildEnv,
1112
isEnterprise,
1213
getGenuineMongoDB,
14+
identifyServerName,
1315
} from '../src/index';
1416

1517
describe('mongodb-build-info', function () {
@@ -428,4 +430,67 @@ describe('mongodb-build-info', function () {
428430
expect(isGenuine.serverName).to.equal('mongodb');
429431
});
430432
});
433+
434+
context('identifyServerName', function () {
435+
function fail() {
436+
return Promise.reject(new Error('Should not be called'));
437+
}
438+
439+
it('reports CosmosDB', async function () {
440+
for (const uri of fixtures.COSMOS_DB_URI) {
441+
const result = await identifyServerName(uri, fail, fail);
442+
expect(result).to.equal('cosmosdb');
443+
}
444+
});
445+
446+
it('reports DocumentDB', async function () {
447+
for (const uri of fixtures.DOCUMENT_DB_URIS) {
448+
const result = await identifyServerName(uri, fail, fail);
449+
expect(result).to.equal('documentdb');
450+
}
451+
});
452+
453+
it('reports Firestore', async function () {
454+
for (const uri of fixtures.FIRESTORE_URIS) {
455+
const result = await identifyServerName(uri, fail, fail);
456+
expect(result).to.equal('firestore');
457+
}
458+
});
459+
460+
it('reports FerretDB', async function () {
461+
const result = await identifyServerName(
462+
'',
463+
(req) => {
464+
if ('buildInfo' in req) {
465+
return Promise.resolve({
466+
ferretdb: {},
467+
});
468+
} else {
469+
return Promise.resolve({});
470+
}
471+
},
472+
fail,
473+
);
474+
expect(result).to.equal('ferretdb');
475+
});
476+
477+
it('reports PG DocumentDB', async function () {
478+
const result = await identifyServerName(
479+
'',
480+
() => Promise.resolve({}),
481+
(req) => {
482+
if ('getParameter' in req) {
483+
return Promise.reject(
484+
new Error(
485+
'function documentdb_api.get_parameter(boolean, boolean, text[]) does not exist',
486+
),
487+
);
488+
} else {
489+
return Promise.resolve({});
490+
}
491+
},
492+
);
493+
expect(result).to.equal('pg_documentdb');
494+
});
495+
});
431496
});

0 commit comments

Comments
 (0)