Skip to content

Commit a59ca2e

Browse files
committed
Adds integration test to verify behavior of timezone settings
1 parent fc509ac commit a59ca2e

1 file changed

Lines changed: 103 additions & 0 deletions

File tree

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import * as kbnTestServer from '../../../test_helpers/kbn_server';
10+
11+
function createRoot() {
12+
return kbnTestServer.createRoot({
13+
logging: {
14+
silent: true, // set "true" in kbnTestServer
15+
timezone: 'GMT',
16+
appenders: {
17+
'test-timezone-SAJHB': {
18+
kind: 'console',
19+
layout: {
20+
highlight: false,
21+
kind: 'pattern',
22+
pattern: '%date{ISO8601_TZ}{Africa/Johannesburg}',
23+
},
24+
},
25+
'test-timezone-use-root': {
26+
kind: 'console',
27+
layout: {
28+
highlight: false,
29+
kind: 'pattern',
30+
pattern: '%date',
31+
},
32+
},
33+
},
34+
loggers: [
35+
{
36+
context: 'datemodifiertimezone',
37+
appenders: ['test-timezone-SAJHB'],
38+
level: 'info',
39+
},
40+
{
41+
context: 'mainloggingtimezone',
42+
appenders: ['test-timezone-use-root'],
43+
level: 'info',
44+
},
45+
],
46+
},
47+
});
48+
}
49+
50+
const nonGlobalRegex = new RegExp('^[0-9]+');
51+
52+
describe('logging service', () => {
53+
describe('logs date with timezone specified', () => {
54+
let root: ReturnType<typeof createRoot>;
55+
let mockConsoleLog: jest.SpyInstance;
56+
beforeAll(async () => {
57+
mockConsoleLog = jest.spyOn(global.console, 'log');
58+
root = createRoot();
59+
60+
await root.setup();
61+
}, 30000);
62+
63+
beforeEach(() => {
64+
mockConsoleLog.mockClear();
65+
});
66+
67+
afterAll(async () => {
68+
mockConsoleLog.mockRestore();
69+
await root.shutdown();
70+
});
71+
72+
it('uses specified date modifier timezone', () => {
73+
const logger = root.logger.get('datemodifiertimezone');
74+
75+
logger.info('info from "datemodifiertimezone" context');
76+
77+
expect(mockConsoleLog).toHaveBeenCalledTimes(1);
78+
const dateTimezoneModifier = mockConsoleLog.mock.calls[0][0]
79+
.split('.')[1]
80+
.replace(nonGlobalRegex, 'x');
81+
expect(dateTimezoneModifier.endsWith('+02:00')).toBe(true);
82+
});
83+
84+
it('uses root logging date timezone', () => {
85+
const logger = root.logger.get('mainloggingtimezone');
86+
87+
logger.info('info from "mainloggingtimezone" context');
88+
const dateTimezoneModifier = mockConsoleLog.mock.calls[0][0]
89+
.split('.')[1]
90+
.replace(nonGlobalRegex, 'x');
91+
expect(dateTimezoneModifier.endsWith('-05:00')).toBe(true);
92+
});
93+
94+
it('falls back to the root settings', () => {
95+
const logger = root.logger.get('fallback');
96+
97+
logger.info('info from "fallback" context');
98+
99+
// output muted by silent: true
100+
expect(mockConsoleLog).toHaveBeenCalledTimes(0);
101+
});
102+
});
103+
});

0 commit comments

Comments
 (0)