8000 Update redisAppender-test.js · LikeABossProgrammer/log4js-node@20ad278 · GitHub
[go: up one dir, main page]

Skip to content

Commit 20ad278

Browse files
authored
Update redisAppender-test.js
1 parent 0162852 commit 20ad278

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

test/tap/redisAppender-test.js

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const sandbox = require('sandboxed-module');
77
function setupLogging(category, options) {
88
const msgs = [];
99

10-
const redisHost = {
10+
const redisCredentials = {
1111
type: options.type,
1212
host: options.host,
1313
port: options.port,
@@ -17,7 +17,12 @@ function setupLogging(category, options) {
1717
};
1818

1919
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+
2126
return {
2227
on: function (event, callback) {
2328
callback('throw redis error #1');
@@ -77,14 +82,13 @@ function setupLogging(category, options) {
7782
layouts: fakeLayouts,
7883
console: fakeConsole,
7984
messages: msgs,
80-
redishost: redisHost
85+
credentials: redisCredentials
8186
};
8287
}
8388

8489
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]));
8892
}
8993
}
9094

@@ -95,23 +99,25 @@ test('log4js redisAppender', (batch) => {
9599
const result = setupLogging('redis setup', {
96100
host: '127.0.0.1',
97101
port: 6739,
98-
pass: '',
102+
pass: '123456',
99103
channel: 'log',
100104
type: 'redis',
101105
layout: {
102-
type: 'tester'
106+
type: 'pattern',
107+
pattern: '%d{yyyy-MM-dd hh:mm:ss:SSS}#%p#%m'
103108
}
104109
});
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');
113118
assert.end();
114119
});
120+
115121
t.end();
116122
});
117123

@@ -123,7 +129,8 @@ test('log4js redisAppender', (batch) => {
123129
channel: 'log',
124130
type: 'redis',
125131
layout: {
126-
type: 'tester'
132+
type: 'pattern',
133+
pattern: '%d{yyyy-MM-dd hh:mm:ss:SSS}#%p#%m'
127134
}
128135
});
129136

@@ -134,6 +141,7 @@ test('log4js redisAppender', (batch) => {
134141
t.end();
135142
});
136143

144+
137145
batch.test('config with layout', (t) => {
138146
const result = setupLogging('config with layout', {
139147
layout: {
@@ -152,7 +160,8 @@ test('log4js redisAppender', (batch) => {
152160
channel: 'log',
153161
type: 'redis',
154162
layout: {
155-
type: 'tester'
163+
type: 'pattern',
164+
pattern: '%d{yyyy-MM-dd hh:mm:ss:SSS}#%p#%m'
156165
}
157166
});
158167
setTimeout(() => {

0 commit comments

Comments
 (0)
0