Loki: Remove any from public/app/plugins/datasource/loki/live_streams.test.ts (#55545)

Co-authored-by: gitstart <gitstart@gitstart.com>
Co-authored-by: gitstart <gitstart@users.noreply.github.com>
Co-authored-by: Matheus Benini Ferreira <88898100+MatheusBeniniF@users.noreply.github.com>
Co-authored-by: Nitesh Singh <nitesh.singh@gitstart.dev>
Co-authored-by: Thiago Nascimbeni <tnascimbeni@gmail.com>
Co-authored-by: Rafael Toledo <87545086+Toledodev@users.noreply.github.com>
Co-authored-by: Murilo Amaral <87545137+MuriloAmarals@users.noreply.github.com>
Co-authored-by: Rubens Rafael <70234898+RubensRafael@users.noreply.github.com>
Co-authored-by: Júlio Piubello da Silva Cabral <julio.piubello@gitstart.dev>

Co-authored-by: gitstart <gitstart@users.noreply.github.com>
Co-authored-by: gitstart <gitstart@gitstart.com>
Co-authored-by: Matheus Benini Ferreira <88898100+MatheusBeniniF@users.noreply.github.com>
Co-authored-by: Nitesh Singh <nitesh.singh@gitstart.dev>
Co-authored-by: Thiago Nascimbeni <tnascimbeni@gmail.com>
Co-authored-by: Rafael Toledo <87545086+Toledodev@users.noreply.github.com>
Co-authored-by: Murilo Amaral <87545137+MuriloAmarals@users.noreply.github.com>
Co-authored-by: Rubens Rafael <70234898+RubensRafael@users.noreply.github.com>
Co-authored-by: Júlio Piubello da Silva Cabral <julio.piubello@gitstart.dev>
This commit is contained in:
GitStart 2022-09-26 20:12:53 +05:30 committed by GitHub
parent 9aa61ddd0e
commit ac875a1329
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 18 deletions

View File

@ -6713,15 +6713,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "1"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"] [0, 0, 0, "Unexpected any. Specify a different type.", "2"]
], ],
"public/app/plugins/datasource/loki/LiveStreams.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
[0, 0, 0, "Unexpected any. Specify a different type.", "6"]
],
"public/app/plugins/datasource/loki/LiveStreams.ts:5381": [ "public/app/plugins/datasource/loki/LiveStreams.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"] [0, 0, 0, "Unexpected any. Specify a different type.", "0"]
], ],

View File

@ -8,7 +8,11 @@ import { DataFrame, DataFrameView, formatLabels, Labels } from '@grafana/data';
import { LiveStreams } from './LiveStreams'; import { LiveStreams } from './LiveStreams';
import { LokiTailResponse } from './types'; import { LokiTailResponse } from './types';
let fakeSocket: Subject<any>; interface ErrorException extends Error {
code?: number;
}
let fakeSocket: Subject<LokiTailResponse>;
jest.mock('rxjs/webSocket', () => { jest.mock('rxjs/webSocket', () => {
return { return {
__esModule: true, __esModule: true,
@ -32,7 +36,7 @@ describe('Live Stream Tests', () => {
}; };
it('reads the values into the buffer', (done) => { it('reads the values into the buffer', (done) => {
fakeSocket = new Subject<any>(); fakeSocket = new Subject<LokiTailResponse>();
const labels: Labels = { job: 'varlogs' }; const labels: Labels = { job: 'varlogs' };
const target = makeTarget('fake', labels); const target = makeTarget('fake', labels);
const stream = new LiveStreams().getStream(target); const stream = new LiveStreams().getStream(target);
@ -69,7 +73,7 @@ describe('Live Stream Tests', () => {
}); });
it('returns the same subscription if the url matches existing one', () => { it('returns the same subscription if the url matches existing one', () => {
fakeSocket = new Subject<any>(); fakeSocket = new Subject<LokiTailResponse>();
const liveStreams = new LiveStreams(); const liveStreams = new LiveStreams();
const stream1 = liveStreams.getStream(makeTarget('url_to_match')); const stream1 = liveStreams.getStream(makeTarget('url_to_match'));
const stream2 = liveStreams.getStream(makeTarget('url_to_match')); const stream2 = liveStreams.getStream(makeTarget('url_to_match'));
@ -77,7 +81,7 @@ describe('Live Stream Tests', () => {
}); });
it('returns new subscription when the previous unsubscribed', () => { it('returns new subscription when the previous unsubscribed', () => {
fakeSocket = new Subject<any>(); fakeSocket = new Subject<LokiTailResponse>();
const liveStreams = new LiveStreams(); const liveStreams = new LiveStreams();
const stream1 = liveStreams.getStream(makeTarget('url_to_match')); const stream1 = liveStreams.getStream(makeTarget('url_to_match'));
const subscription = stream1.subscribe({ const subscription = stream1.subscribe({
@ -91,9 +95,9 @@ describe('Live Stream Tests', () => {
it('returns new subscription when the previous is unsubscribed and correctly unsubscribes from source', () => { it('returns new subscription when the previous is unsubscribed and correctly unsubscribes from source', () => {
let unsubscribed = false; let unsubscribed = false;
fakeSocket = new Observable(() => { const fakeSocket = new Observable(() => {
return () => (unsubscribed = true); return () => (unsubscribed = true);
}) as any; });
jest.spyOn(rxJsWebSocket, 'webSocket').mockReturnValue(fakeSocket as rxJsWebSocket.WebSocketSubject<unknown>); jest.spyOn(rxJsWebSocket, 'webSocket').mockReturnValue(fakeSocket as rxJsWebSocket.WebSocketSubject<unknown>);
const liveStreams = new LiveStreams(); const liveStreams = new LiveStreams();
@ -105,7 +109,7 @@ describe('Live Stream Tests', () => {
expect(unsubscribed).toBe(true); expect(unsubscribed).toBe(true);
}); });
it('should reconnect when abnormal error', async () => { it('should reconnect when abnormal error', async () => {
const abnormalError = new Error('weird error') as any; const abnormalError = new Error('weird error') as ErrorException;
abnormalError.code = 1006; abnormalError.code = 1006;
const logStreamBeforeError = of({ const logStreamBeforeError = of({
streams: [ streams: [
@ -127,7 +131,7 @@ describe('Live Stream Tests', () => {
}); });
const errorStream = throwError(abnormalError); const errorStream = throwError(abnormalError);
let retries = 0; let retries = 0;
fakeSocket = of({}).pipe( const fakeSocket = of({}).pipe(
mergeMap(() => { mergeMap(() => {
// When subscribed first time, return logStream and errorStream // When subscribed first time, return logStream and errorStream
if (retries++ === 0) { if (retries++ === 0) {
@ -136,7 +140,7 @@ describe('Live Stream Tests', () => {
// When re-subsribed after abnormal error, return just logStream // When re-subsribed after abnormal error, return just logStream
return logStreamAfterError; return logStreamAfterError;
}) })
) as any; );
jest.spyOn(rxJsWebSocket, 'webSocket').mockReturnValue(fakeSocket as rxJsWebSocket.WebSocketSubject<unknown>); jest.spyOn(rxJsWebSocket, 'webSocket').mockReturnValue(fakeSocket as rxJsWebSocket.WebSocketSubject<unknown>);
const liveStreams = new LiveStreams(); const liveStreams = new LiveStreams();
await expect(liveStreams.getStream(makeTarget('url_to_match'), 100)).toEmitValuesWith((received) => { await expect(liveStreams.getStream(makeTarget('url_to_match'), 100)).toEmitValuesWith((received) => {