|
15 | 15 | */
|
16 | 16 |
|
17 | 17 | import { it, expect } from 'vitest';
|
18 |
| -import { BaseService, ServiceState } from './service'; |
19 |
| - |
| 18 | +import { BaseService, ServiceState, StartupLog } from './service'; |
| 19 | +import { LogLevel } from './modules/logging'; |
| 20 | +import { getMockLogger } from './tests/mock/mock_logger'; |
20 | 21 | class TestService extends BaseService {
|
21 |
| - constructor() { |
22 |
| - super(); |
| 22 | + constructor(startUpLogs?: StartupLog[]) { |
| 23 | + super(startUpLogs); |
23 | 24 | }
|
24 | 25 |
|
25 | 26 | start(): void {
|
| 27 | + super.start(); |
26 | 28 | this.setState(ServiceState.Running);
|
27 | 29 | this.startPromise.resolve();
|
28 | 30 | }
|
@@ -64,6 +66,30 @@ it('should return correct state when getState() is called', () => {
|
64 | 66 | expect(service.getState()).toBe(ServiceState.Failed);
|
65 | 67 | });
|
66 | 68 |
|
| 69 | +it('should log startupLogs on start', () => { |
| 70 | + const startUpLogs: StartupLog[] = [ |
| 71 | + { |
| 72 | + level: LogLevel.WARNING, |
| 73 | + message: 'warn message', |
| 74 | + params: [1, 2] |
| 75 | + }, |
| 76 | + { |
| 77 | + level: LogLevel.ERROR, |
| 78 | + message: 'error message', |
| 79 | + params: [3, 4] |
| 80 | + }, |
| 81 | + ]; |
| 82 | + |
| 83 | + const logger = getMockLogger(); |
| 84 | + const service = new TestService(startUpLogs); |
| 85 | + service.setLogger(logger); |
| 86 | + service.start(); |
| 87 | + |
| 88 | + expect(logger.log).toHaveBeenCalledTimes(2); |
| 89 | + expect(logger.log).toHaveBeenNthCalledWith(1, LogLevel.WARNING, 'warn message', 1, 2); |
| 90 | + expect(logger.log).toHaveBeenNthCalledWith(2, LogLevel.ERROR, 'error message', 3, 4); |
| 91 | +}); |
| 92 | + |
67 | 93 | it('should return an appropraite promise when onRunning() is called', () => {
|
68 | 94 | const service1 = new TestService();
|
69 | 95 | const onRunning1 = service1.onRunning();
|
|
0 commit comments