File tree Expand file tree Collapse file tree 2 files changed +52
-3
lines changed
packages/mongodb-log-writer/src Expand file tree Collapse file tree 2 files changed +52
-3
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,48 @@ describe('MongoLogManager', function () {
3131 sinon . restore ( ) ;
3232 } ) ;
3333
34+ it ( 'constructor throws with invalid prefixes' , function ( ) {
35+ expect ( ( ) => {
36+ new MongoLogManager ( {
37+ directory,
38+ retentionDays,
39+ prefix : '%asdabs/' ,
40+ onwarn,
41+ onerror,
42+ } ) ;
43+ } ) . to . throw ( ) ;
44+
45+ expect ( ( ) => {
46+ new MongoLogManager ( {
47+ directory,
48+ retentionDays,
49+ prefix : '$$$$' ,
50+ onwarn,
51+ onerror,
52+ } ) ;
53+ } ) . to . throw ( ) ;
54+
55+ expect ( ( ) => {
56+ new MongoLogManager ( {
57+ directory,
58+ retentionDays,
59+ prefix : 'abc_' ,
60+ onwarn,
61+ onerror,
62+ } ) ;
63+ } ) . not . to . throw ( ) ;
64+
65+ expect ( ( ) => {
66+ new MongoLogManager ( {
67+ directory,
68+ retentionDays,
69+ prefix : 'something' ,
70+ onwarn,
71+ onerror,
72+ } ) ;
73+ } ) . not . to . throw ( ) ;
74+ } ) ;
75+
3476 it ( 'allows creating and writing to log files' , async function ( ) {
3577 const manager = new MongoLogManager ( {
3678 directory,
@@ -144,8 +186,8 @@ describe('MongoLogManager', function () {
144186 directory,
145187 retentionDays,
146188 retentionGB : 3 ,
147- onerror,
148189 onwarn,
190+ onerror,
149191 } ) ;
150192
151193 const offset = Math . floor ( Date . now ( ) / 1000 ) ;
Original file line number Diff line number Diff line change @@ -21,10 +21,10 @@ interface MongoLogOptions {
2121 retentionGB ?: number ;
2222 /** Prefix to use for the log files */
2323 prefix ?: string ;
24- /** A handler for warnings related to a specific filesystem path. */
25- onerror : ( err : Error , path : string ) => unknown | Promise < void > ;
2624 /** A handler for errors related to a specific filesystem path. */
2725 onerror : ( err : Error , path : string ) => unknown | Promise < void > ;
26+ /** A handler for warnings related to a specific filesystem path. */
27+ onwarn : ( err : Error , path : string ) => unknown | Promise < void > ;
2828}
2929
3030/**
@@ -36,6 +36,13 @@ export class MongoLogManager {
3636 _options : MongoLogOptions ;
3737
3838 constructor ( options : MongoLogOptions ) {
39+ if ( options . prefix ) {
40+ if ( ! / ^ [ a - z 0 - 9 _ ] + $ / i. test ( options . prefix ) ) {
41+ throw new Error (
42+ 'Prefix must only contain letters, numbers, and underscores'
43+ ) ;
44+ }
45+ }
3946 this . _options = options ;
4047 }
4148
You can’t perform that action at this time.
0 commit comments