mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 19:54:10 -06:00
Chore: Replace deprecated toPromise() calls with lastValueFrom (#54234)
This commit is contained in:
parent
6e4900dc45
commit
d79830fdd7
@ -30,10 +30,15 @@ import {
|
|||||||
import mockJson from './mockJsonResponse.json';
|
import mockJson from './mockJsonResponse.json';
|
||||||
import mockServiceGraph from './mockServiceGraph.json';
|
import mockServiceGraph from './mockServiceGraph.json';
|
||||||
|
|
||||||
|
let mockObservable: () => Observable<any>;
|
||||||
jest.mock('@grafana/runtime', () => {
|
jest.mock('@grafana/runtime', () => {
|
||||||
return {
|
return {
|
||||||
...jest.requireActual('@grafana/runtime'),
|
...jest.requireActual('@grafana/runtime'),
|
||||||
reportInteraction: jest.fn(),
|
reportInteraction: jest.fn(),
|
||||||
|
getBackendSrv: () => ({
|
||||||
|
fetch: mockObservable,
|
||||||
|
_request: mockObservable,
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -343,6 +348,24 @@ describe('Tempo data source', () => {
|
|||||||
const lokiDS4 = ds4.getLokiSearchDS();
|
const lokiDS4 = ds4.getLokiSearchDS();
|
||||||
expect(lokiDS4).toBe(undefined);
|
expect(lokiDS4).toBe(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('test the testDatasource function', () => {
|
||||||
|
it('should return a success msg if response.ok is true', async () => {
|
||||||
|
mockObservable = () => of({ ok: true });
|
||||||
|
const ds = new TempoDatasource(defaultSettings);
|
||||||
|
const response = await ds.testDatasource();
|
||||||
|
expect(response.status).toBe('success');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('test the metadataRequest function', () => {
|
||||||
|
it('should return the last value from the observed stream', async () => {
|
||||||
|
mockObservable = () => of('321', '123', '456');
|
||||||
|
const ds = new TempoDatasource(defaultSettings);
|
||||||
|
const response = await ds.metadataRequest('/api/search/tags');
|
||||||
|
expect(response).toBe('456');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Tempo apm table', () => {
|
describe('Tempo apm table', () => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { identity, pick, pickBy, groupBy, startCase } from 'lodash';
|
import { identity, pick, pickBy, groupBy, startCase } from 'lodash';
|
||||||
import { EMPTY, from, merge, Observable, of, throwError } from 'rxjs';
|
import { EMPTY, from, lastValueFrom, merge, Observable, of, throwError } from 'rxjs';
|
||||||
import { catchError, concatMap, map, mergeMap, toArray } from 'rxjs/operators';
|
import { catchError, concatMap, map, mergeMap, toArray } from 'rxjs/operators';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -336,7 +336,7 @@ export class TempoDatasource extends DataSourceWithBackend<TempoQuery, TempoJson
|
|||||||
}
|
}
|
||||||
|
|
||||||
async metadataRequest(url: string, params = {}) {
|
async metadataRequest(url: string, params = {}) {
|
||||||
return await this._request(url, params, { method: 'GET', hideFromInspector: true }).toPromise();
|
return await lastValueFrom(this._request(url, params, { method: 'GET', hideFromInspector: true }));
|
||||||
}
|
}
|
||||||
|
|
||||||
private _request(apiUrl: string, data?: any, options?: Partial<BackendSrvRequest>): Observable<Record<string, any>> {
|
private _request(apiUrl: string, data?: any, options?: Partial<BackendSrvRequest>): Observable<Record<string, any>> {
|
||||||
@ -353,7 +353,7 @@ export class TempoDatasource extends DataSourceWithBackend<TempoQuery, TempoJson
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: `${this.instanceSettings.url}/api/echo`,
|
url: `${this.instanceSettings.url}/api/echo`,
|
||||||
};
|
};
|
||||||
const response = await getBackendSrv().fetch<any>(options).toPromise();
|
const response = await lastValueFrom(getBackendSrv().fetch<any>(options));
|
||||||
|
|
||||||
if (response?.ok) {
|
if (response?.ok) {
|
||||||
return { status: 'success', message: 'Data source is working' };
|
return { status: 'success', message: 'Data source is working' };
|
||||||
|
Loading…
Reference in New Issue
Block a user