@@ -13,12 +13,8 @@ const { ReadPreference } = require('../mongodb');
13
13
const { MongoCredentials } = require ( '../mongodb' ) ;
14
14
const { MongoClient, MongoParseError, ServerApiVersion } = require ( '../mongodb' ) ;
15
15
const { MongoLogger } = require ( '../mongodb' ) ;
16
- const {
17
- SeverityLevel,
18
- MongoLoggableComponent,
19
- MongoLoggerEnvOptions
20
- // eslint-disable-next-line no-restricted-modules
21
- } = require ( '../../src/mongo_logger' ) ;
16
+ // eslint-disable-next-line no-restricted-modules
17
+ const { SeverityLevel, MongoLoggableComponent } = require ( '../../src/mongo_logger' ) ;
22
18
const sinon = require ( 'sinon' ) ;
23
19
const { Writable } = require ( 'stream' ) ;
24
20
@@ -846,7 +842,9 @@ describe('MongoOptions', function () {
846
842
} ) ;
847
843
const log = { t : new Date ( ) , c : 'constructorStdErr' , s : 'error' } ;
848
844
client . options . mongoLoggerOptions . logDestination . write ( log ) ;
849
- expect ( stderrStub . write ) . calledWith ( inspect ( log , { breakLength : Infinity , compact : true } ) ) ;
845
+ expect ( stderrStub . write ) . calledWith (
846
+ inspect ( log , { breakLength : Infinity , compact : true } )
847
+ ) ;
850
848
} ) ;
851
849
} ) ;
852
850
@@ -874,7 +872,9 @@ describe('MongoOptions', function () {
874
872
} ) ;
875
873
const log = { t : new Date ( ) , c : 'constructorStdOut' , s : 'error' } ;
876
874
client . options . mongoLoggerOptions . logDestination . write ( log ) ;
877
- expect ( stdoutStub . write ) . calledWith ( inspect ( log , { breakLength : Infinity , compact : true } ) ) ;
875
+ expect ( stdoutStub . write ) . calledWith (
876
+ inspect ( log , { breakLength : Infinity , compact : true } )
877
+ ) ;
878
878
} ) ;
879
879
} ) ;
880
880
@@ -893,7 +893,7 @@ describe('MongoOptions', function () {
893
893
} ) ;
894
894
} ) ;
895
895
} ) ;
896
- describe . only ( 'component severities' , function ( ) {
896
+ describe ( 'component severities' , function ( ) {
897
897
const components = Object . values ( MongoLoggableComponent ) ;
898
898
const env_component_names = [
899
899
'MONGODB_LOG_COMMAND' ,
@@ -912,37 +912,69 @@ describe('MongoOptions', function () {
912
912
[ components [ i ] ] : severityLevel
913
913
}
914
914
} ) ;
915
- expect ( client . options . mongoLoggerOptions . componentSeverities [ components [ i ] ] ) . to . equal (
916
- severityLevel
917
- ) ;
915
+ for ( const [ curComponent , curSeverity ] of Object . entries (
916
+ client . options . mongoLoggerOptions . componentSeverities
917
+ ) ) {
918
+ if ( curComponent === components [ i ] ) {
919
+ expect ( curSeverity ) . to . equal ( severityLevel ) ;
920
+ } else {
921
+ expect ( curSeverity ) . to . equal ( SeverityLevel . OFF ) ;
922
+ }
923
+ }
918
924
}
919
925
} ) ;
920
926
}
921
927
} ) ;
922
928
context ( 'when both client and environment option is provided' , function ( ) {
923
929
for ( let i = 0 ; i < components . length ; i ++ ) {
924
- beforeEach ( function ( ) {
930
+ it ( `it stores severity level for ${ components [ i ] } component correctly (client options have precedence)` , function ( ) {
925
931
process . env [ env_component_names [ i ] ] = 'emergency' ;
926
- } ) ;
927
-
928
- afterEach ( function ( ) {
929
- process . env [ env_component_names [ i ] ] = undefined ;
930
- } ) ;
931
-
932
- it ( `it stores severity levels for ${ components [ i ] } component correctly (client options have precedence)` , function ( ) {
933
932
for ( const severityLevel of Object . values ( SeverityLevel ) ) {
934
933
const client = new MongoClient ( 'mongodb://a/' , {
935
934
[ loggerFeatureFlag ] : true ,
936
935
mongodbLogComponentSeverities : {
937
936
[ components [ i ] ] : severityLevel
938
937
}
939
938
} ) ;
940
- expect ( client . options . mongoLoggerOptions . componentSeverities [ components [ i ] ] ) . to . equal (
941
- severityLevel
942
- ) ;
939
+ for ( const [ curComponent , curSeverity ] of Object . entries (
940
+ client . options . mongoLoggerOptions . componentSeverities
941
+ ) ) {
942
+ if ( curComponent === components [ i ] ) {
943
+ expect ( curSeverity ) . to . equal ( severityLevel ) ;
944
+ } else {
945
+ expect ( curSeverity ) . to . equal ( SeverityLevel . OFF ) ;
946
+ }
947
+ }
948
+ process . env [ env_component_names [ i ] ] = undefined ;
943
949
}
944
950
} ) ;
945
- } ;
951
+ }
952
+ } ) ;
953
+ context ( 'when default is provided' , function ( ) {
954
+ it ( 'unspecified components have default value, while specified components retain value' , function ( ) {
955
+ for ( let i = 0 ; i < components . length ; i ++ ) {
956
+ for ( const severityLevel of Object . values ( SeverityLevel ) ) {
957
+ for ( const severityLevel2 of Object . values ( SeverityLevel ) ) {
958
+ const client = new MongoClient ( 'mongodb://a/' , {
959
+ [ loggerFeatureFlag ] : true ,
960
+ mongodbLogComponentSeverities : {
961
+ [ components [ i ] ] : severityLevel ,
962
+ default : severityLevel2
963
+ }
964
+ } ) ;
965
+ for ( const [ curComponent , curSeverity ] of Object . entries (
966
+ client . options . mongoLoggerOptions . componentSeverities
967
+ ) ) {
968
+ if ( curComponent === components [ i ] ) {
969
+ expect ( curSeverity ) . to . equal ( severityLevel ) ;
970
+ } else {
971
+ expect ( curSeverity ) . to . equal ( severityLevel2 ) ;
972
+ }
973
+ }
974
+ }
975
+ }
976
+ }
977
+ } ) ;
946
978
} ) ;
947
979
} ) ;
948
980
} ) ;
0 commit comments