11import { expect } from 'chai' ;
2+
23import * as fixtures from './fixtures' ;
34import {
45 isAtlas ,
@@ -10,6 +11,7 @@ import {
1011 getBuildEnv ,
1112 isEnterprise ,
1213 getGenuineMongoDB ,
14+ identifyServerName ,
1315} from '../src/index' ;
1416
1517describe ( '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