-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: dblock <[email protected]>
- Loading branch information
Showing
5 changed files
with
128 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
import { Logger, LogLevel } from '../src/Logger' | ||
|
||
describe('Logger', () => { | ||
let log: jest.Mock | ||
|
||
beforeEach(() => { | ||
log = console.log = jest.fn() | ||
}) | ||
|
||
afterEach(() => { | ||
log.mockClear() | ||
}) | ||
|
||
describe('at default log level', () => { | ||
const logger = new Logger() | ||
|
||
test('sets log level at warn', () => { | ||
expect(logger.level).toEqual(LogLevel.warn) | ||
}) | ||
|
||
test('does not log info level messages', () => { | ||
logger.log('log') | ||
logger.error('error') | ||
logger.warn('warn') | ||
logger.info('info') | ||
expect(log.mock.calls).toEqual([ | ||
['log'], | ||
['[ERROR] error'], | ||
['[WARNING] warn'] | ||
]) | ||
}) | ||
}) | ||
|
||
describe('at info log level', () => { | ||
const logger = new Logger(LogLevel.info) | ||
|
||
test('sets log level at info', () => { | ||
expect(logger.level).toEqual(LogLevel.info) | ||
}) | ||
|
||
test('logs all messages', () => { | ||
logger.log('log') | ||
logger.error('error') | ||
logger.warn('warn') | ||
logger.info('info') | ||
expect(log.mock.calls).toEqual([ | ||
['log'], | ||
['[ERROR] error'], | ||
['[WARNING] warn'], | ||
['[INFO] info'] | ||
]) | ||
}) | ||
}) | ||
|
||
describe('at warn log level', () => { | ||
const logger = new Logger(LogLevel.warn) | ||
|
||
test('sets log level at warn', () => { | ||
expect(logger.level).toEqual(LogLevel.warn) | ||
}) | ||
|
||
test('does not log info messages', () => { | ||
logger.log('log') | ||
logger.error('error') | ||
logger.warn('warn') | ||
logger.info('info') | ||
expect(log.mock.calls).toEqual([ | ||
['log'], | ||
['[ERROR] error'], | ||
['[WARNING] warn'] | ||
]) | ||
}) | ||
}) | ||
|
||
describe('at error log level', () => { | ||
const logger = new Logger(LogLevel.error) | ||
|
||
test('sets log level at error', () => { | ||
expect(logger.level).toEqual(LogLevel.error) | ||
}) | ||
|
||
test('does not log warn and info messages', () => { | ||
logger.log('log') | ||
logger.error('error') | ||
logger.warn('warn') | ||
logger.info('info') | ||
expect(log.mock.calls).toEqual([ | ||
['log'], | ||
['[ERROR] error'] | ||
]) | ||
}) | ||
}) | ||
}) |