@@ -7,7 +7,7 @@ const sandbox = require('sandboxed-module');
7
7
function setupLogging ( category , options ) {
8
8
const msgs = [ ] ;
9
9
10
- const redisHost = {
10
+ const redisCredentials = {
11
11
type : options . type ,
12
12
host : options . host ,
13
13
port : options . port ,
@@ -17,7 +17,12 @@ function setupLogging(category, options) {
17
17
} ;
18
18
19
19
const fakeRedis = {
20
- createClient : function ( port , post , optionR ) {
20
+ createClient : function ( port , host , optionR ) {
21
+ this . port = port ;
22
+ this . host = host ;
23
+ this . optionR = { } ;
24
+ this . optionR . auth_pass = optionR . pass ;
25
+
21
26
return {
22
27
on : function ( event , callback ) {
23
28
callback ( 'throw redis error #1' ) ;
@@ -77,14 +82,13 @@ function setupLogging(category, options) {
77
82
layouts : fakeLayouts ,
78
83
console : fakeConsole ,
79
84
messages : msgs ,
80
- redishost : redisHost
85
+ credentials : redisCredentials
81
86
} ;
82
87
}
83
88
84
89
function checkMessages ( assert , result ) {
85
- for ( let i = 0 ; i < result . messages . length ; ++ i ) {
86
- assert . equal ( result . messages [ i ] . channel , 'log' ) ;
87
- assert . ok ( new RegExp ( `.+Log event #${ i + 1 } ` ) . test ( result . messages [ i ] . text ) ) ;
90
+ for ( let i = 0 ; i < result . messages . length ; i ++ ) {
91
+ assert . ok ( new RegExp ( `Log event #${ i + 1 } ` ) . test ( result . messages [ i ] ) ) ;
88
92
}
89
93
}
90
94
@@ -95,23 +99,25 @@ test('log4js redisAppender', (batch) => {
95
99
const result = setupLogging ( 'redis setup' , {
96
100
host : '127.0.0.1' ,
97
101
port : 6739 ,
98
- pass : '' ,
102
+ pass : '123456 ' ,
99
103
channel : 'log' ,
100
104
type : 'redis' ,
101
105
layout : {
102
- type : 'tester'
106
+ type : 'pattern' ,
107
+ pattern : '%d{yyyy-MM-dd hh:mm:ss:SSS}#%p#%m'
103
108
}
104
109
} ) ;
105
-
106
- t . test ( 'redis redishost should match' , ( assert ) => {
107
- assert . equal ( result . redishost . host , '127.0.0.1' ) ;
108
- assert . equal ( result . redishost . port , 6739 ) ;
109
- assert . equal ( result . redishost . pass , '' ) ;
110
- assert . equal ( result . redishost . channel , 'log ' ) ;
111
- assert . equal ( result . redishost . type , 'redis ' ) ;
112
- assert . equal ( result . redishost . layout . type , 'tester ' ) ;
110
+ t . test ( 'redis credentials should match' , ( assert ) => {
111
+ assert . equal ( result . credentials . host , '127.0.0.1' ) ;
112
+ assert . equal ( result . credentials . port , 6739 ) ;
113
+ assert . equal ( result . credentials . pass , '123456' ) ;
114
+ assert . equal ( result . credentials . channel , 'log ' ) ;
115
+ assert . equal ( result . credentials . type , 'redis ' ) ;
116
+ assert . equal ( result . credentials . layout . type , 'pattern ' ) ;
117
+ assert . equal ( result . credentials . layout . pattern , '%d{yyyy-MM-dd hh:mm:ss:SSS}#%p#%m ' ) ;
113
118
assert . end ( ) ;
114
119
} ) ;
120
+
115
121
t . end ( ) ;
116
122
} ) ;
117
123
@@ -123,7 +129,8 @@ test('log4js redisAppender', (batch) => {
123
129
channel : 'log' ,
124
130
type : 'redis' ,
125
131
layout : {
126
- type : 'tester'
132
+ type : 'pattern' ,
133
+ pattern : '%d{yyyy-MM-dd hh:mm:ss:SSS}#%p#%m'
127
134
}
128
135
} ) ;
129
136
@@ -134,6 +141,7 @@ test('log4js redisAppender', (batch) => {
134
141
t . end ( ) ;
135
142
} ) ;
136
143
144
+
137
145
batch . test ( 'config with layout' , ( t ) => {
138
146
const result = setupLogging ( 'config with layout' , {
139
147
layout : {
@@ -152,7 +160,8 @@ test('log4js redisAppender', (batch) => {
152
160
channel : 'log' ,
153
161
type : 'redis' ,
154
162
layout : {
155
- type : 'tester'
163
+ type : 'pattern' ,
164
+ pattern : '%d{yyyy-MM-dd hh:mm:ss:SSS}#%p#%m'
156
165
}
157
166
} ) ;
158
167
setTimeout ( ( ) => {
0 commit comments