@@ -229,48 +229,62 @@ describe('instance-detail-helper', function () {
229229 return client as MongoClient ;
230230 }
231231
232- it ( 'should throw if buildInfo was not available' , async function ( ) {
233- const client = createMongoClientMock ( ) ;
234-
235- try {
236- await getInstance ( client ) ;
237- } catch ( e ) {
238- expect ( e ) . to . be . instanceof ( Error ) ;
239- return ;
240- }
232+ context ( 'when errors returned from commands' , function ( ) {
233+ it ( 'should throw if buildInfo was not available' , async function ( ) {
234+ const client = createMongoClientMock ( ) ;
235+
236+ try {
237+ await getInstance ( client ) ;
238+ } catch ( e ) {
239+ expect ( e ) . to . be . instanceof ( Error ) ;
240+ return ;
241+ }
242+
243+ throw new Error ( "getInstance didn't throw" ) ;
244+ } ) ;
241245
242- throw new Error ( "getInstance didn't throw" ) ;
243- } ) ;
246+ it ( 'should handle auth errors gracefully on any command except buildInfo' , async function ( ) {
247+ const client = createMongoClientMock ( {
248+ buildInfo : { } ,
249+ } ) ;
244250
245- it ( 'should handle auth errors gracefully on any command' , async function ( ) {
246- const client = createMongoClientMock ( {
247- buildInfo : { } ,
251+ await getInstance ( client ) ;
248252 } ) ;
249253
250- await getInstance ( client ) ;
251- } ) ;
254+ // eslint-disable-next-line mocha/no-setup-in-describe
255+ [ 'connectionStatus' , 'hostInfo' , 'listDatabases' , 'dbStats' ] . forEach (
256+ ( commandName ) => {
257+ it ( `should throw if server returned an unexpected error on ${ commandName } command` , async function ( ) {
258+ const randomError = new Error ( 'Whoops' ) ;
259+
260+ const client = createMongoClientMock ( {
261+ buildInfo : { } ,
262+ listDatabases : fixtures . LIST_DATABASES_NAME_ONLY ,
263+ [ commandName ] : randomError ,
264+ } ) ;
265+
266+ try {
267+ await getInstance ( client ) ;
268+ } catch ( e ) {
269+ expect ( e ) . to . eq ( randomError ) ;
270+ return ;
271+ }
252272
253- it ( 'should throw if server returned an unexpected error on any command' , async function ( ) {
254- const randomError = new Error ( 'Whoops' ) ;
273+ throw new Error ( "getInstance didn't throw" ) ;
274+ } ) ;
275+ }
276+ ) ;
255277
256- const client = createMongoClientMock ( {
257- connectionStatus : randomError ,
258- getCmdLineOpts : randomError ,
259- hostInfo : randomError ,
260- listDatabases : randomError ,
261- getParameter : randomError ,
262- dbStats : randomError ,
263- buildInfo : { } ,
264- } ) ;
278+ it ( 'should ignore all errors returned from getParameter command' , async function ( ) {
279+ const randomError = new Error ( 'Whoops' ) ;
265280
266- try {
267- await getInstance ( client ) ;
268- } catch ( e ) {
269- expect ( e ) . to . eq ( randomError ) ;
270- return ;
271- }
281+ const client = createMongoClientMock ( {
282+ buildInfo : { } ,
283+ getParameter : randomError ,
284+ } ) ;
272285
273- throw new Error ( "getInstance didn't throw" ) ;
286+ await getInstance ( client ) ;
287+ } ) ;
274288 } ) ;
275289
276290 it ( 'should parse build info' , async function ( ) {
0 commit comments