Skip to content

Commit 8fa3973

Browse files
committed
Call into mongodb-build-info when mocking the MockDataService
1 parent 6ab09ca commit 8fa3973

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

configs/testing-library-compass/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"@testing-library/react": "^12.1.5",
6363
"@testing-library/react-hooks": "^7.0.2",
6464
"@testing-library/user-event": "^13.5.0",
65+
"mongodb-build-info": "^1.8.1",
6566
"mongodb-connection-string-url": "^3.0.1",
6667
"react": "^17.0.2",
6768
"react-redux": "^8.1.3",

configs/testing-library-compass/src/index.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import type {
3434
DataService,
3535
InstanceDetails,
3636
} from 'mongodb-data-service';
37+
import { identifyServerName } from 'mongodb-build-info';
3738
import Sinon from 'sinon';
3839
import React from 'react';
3940
import type {
@@ -175,8 +176,22 @@ export class MockDataService
175176
disconnect(): Promise<void> {
176177
return Promise.resolve();
177178
}
178-
instance(): Promise<InstanceDetails> {
179-
return Promise.resolve({
179+
async instance(): Promise<InstanceDetails> {
180+
const { connectionString } = this.connectionOptions;
181+
const serverName = await identifyServerName({
182+
connectionString,
183+
adminCommand: () =>
184+
Promise.reject(
185+
new Error(
186+
'MockDataService adminCommand: this is a mocked environment; no server commands available.'
187+
)
188+
),
189+
});
190+
const genuineMongoDB = {
191+
serverName,
192+
isGenuine: serverName === 'mongodb' || serverName === 'unknown',
193+
};
194+
return {
180195
auth: {
181196
user: null,
182197
roles: [],
@@ -188,10 +203,7 @@ export class MockDataService
188203
version: '100.0.0',
189204
},
190205
host: {},
191-
genuineMongoDB: {
192-
isGenuine: true,
193-
serverName: 'mongodb',
194-
},
206+
genuineMongoDB,
195207
dataLake: {
196208
isDataLake: false,
197209
version: null,
@@ -200,7 +212,7 @@ export class MockDataService
200212
isAtlas: false,
201213
isLocalAtlas: false,
202214
csfleMode: 'unavailable',
203-
});
215+
};
204216
}
205217
}
206218

0 commit comments

Comments
 (0)