|
1 | 1 | import { AxiosError } from 'axios'; |
2 | | -import { describe, expect, test, vi } from 'vitest'; |
| 2 | +import { http } from 'msw'; |
| 3 | +import { firstValueFrom } from 'rxjs'; |
| 4 | +import { describe, expect, it, test, vi } from 'vitest'; |
3 | 5 |
|
| 6 | +import { server } from '@/mocks/server'; |
4 | 7 | import Instance from '@/services/instance'; |
5 | 8 |
|
6 | 9 | const { useSbaConfig } = vi.hoisted(() => ({ |
@@ -181,4 +184,38 @@ describe('Instance', () => { |
181 | 184 | ); |
182 | 185 | }); |
183 | 186 | }); |
| 187 | + |
| 188 | + describe('streamLogFile', () => { |
| 189 | + const instance = new Instance({ |
| 190 | + id: 'test-id', |
| 191 | + registration: { |
| 192 | + name: 'test', |
| 193 | + healthUrl: '', |
| 194 | + source: '', |
| 195 | + }, |
| 196 | + }); |
| 197 | + |
| 198 | + it('should handle single JSON log line correctly', async () => { |
| 199 | + const payload = '{"foo":"bar"}'; |
| 200 | + server.use( |
| 201 | + http.get( |
| 202 | + '/instances/:instanceId/actuator/logfile', |
| 203 | + () => |
| 204 | + // As per Spring Boot definition: https://docs.spring.io/spring-boot/api/rest/actuator/logfile.html |
| 205 | + new Response(payload, { |
| 206 | + headers: { |
| 207 | + 'Accept-Ranges': 'bytes', |
| 208 | + 'Content-Type': 'text/plain;charset=UTF-8', |
| 209 | + 'Content-Length': payload.length.toString(), |
| 210 | + }, |
| 211 | + }), |
| 212 | + ), |
| 213 | + ); |
| 214 | + |
| 215 | + const source = instance.streamLogfile(0); |
| 216 | + const { addendum } = await firstValueFrom(source); |
| 217 | + |
| 218 | + expect(addendum).toEqual(payload); |
| 219 | + }); |
| 220 | + }); |
184 | 221 | }); |
0 commit comments