test(rootLogger): Redaction formatting

Signed-off-by: Harry Hogg <hhogg@spotify.com>
This commit is contained in:
Harry Hogg
2021-10-05 15:17:32 +01:00
parent f8a7f5723a
commit 3c10980ec5
@@ -15,7 +15,12 @@
*/
import * as winston from 'winston';
import { createRootLogger, getRootLogger, setRootLogger } from './rootLogger';
import {
createRootLogger,
getRootLogger,
setRootLogger,
setRedactionList,
} from './rootLogger';
describe('rootLogger', () => {
it('can replace the default logger', () => {
@@ -30,6 +35,19 @@ describe('rootLogger', () => {
);
});
it('redacts given secrets', () => {
const logger = createRootLogger();
jest.spyOn(logger, 'write');
setRedactionList(['SECRET_1', 'SECRET_2']);
logger.info('Logging SECRET_1 and SECRET_2 but not SECRET_3');
expect(logger.write).toHaveBeenCalledWith(
expect.objectContaining({
message: 'Logging [REDACTED] and [REDACTED] but not SECRET_3',
}),
);
});
describe('createRootLoger', () => {
it('creates a new logger', () => {
const oldLogger = getRootLogger();