mirror of
https://github.com/grafana/grafana.git
synced 2025-01-26 16:27:02 -06:00
Refactor: Use data source UID rather than ID (#62781)
This commit is contained in:
parent
8f96fe5ae9
commit
9893408af9
@ -186,6 +186,57 @@ describe('DataSourceWithBackend', () => {
|
||||
obs = toStreamingDataResponse(rsp, request, standardStreamOptionsProvider);
|
||||
expect(obs).toBeDefined();
|
||||
});
|
||||
|
||||
test('check that getResource uses the data source UID', () => {
|
||||
const { mock, ds } = createMockDatasource();
|
||||
ds.getResource('foo');
|
||||
|
||||
const args = mock.calls[0][0];
|
||||
|
||||
expect(mock.calls.length).toBe(1);
|
||||
expect(args).toMatchObject({
|
||||
headers: {
|
||||
'X-Datasource-Uid': 'abc',
|
||||
'X-Plugin-Id': 'dummy',
|
||||
},
|
||||
method: 'GET',
|
||||
url: '/api/datasources/uid/abc/resources/foo',
|
||||
});
|
||||
});
|
||||
|
||||
test('check that postResource uses the data source UID', () => {
|
||||
const { mock, ds } = createMockDatasource();
|
||||
ds.postResource('foo');
|
||||
|
||||
const args = mock.calls[0][0];
|
||||
|
||||
expect(mock.calls.length).toBe(1);
|
||||
expect(args).toMatchObject({
|
||||
headers: {
|
||||
'X-Datasource-Uid': 'abc',
|
||||
'X-Plugin-Id': 'dummy',
|
||||
},
|
||||
method: 'POST',
|
||||
url: '/api/datasources/uid/abc/resources/foo',
|
||||
});
|
||||
});
|
||||
|
||||
test('check that callHealthCheck uses the data source UID', () => {
|
||||
const { mock, ds } = createMockDatasource();
|
||||
ds.callHealthCheck();
|
||||
|
||||
const args = mock.calls[0][0];
|
||||
|
||||
expect(mock.calls.length).toBe(1);
|
||||
expect(args).toMatchObject({
|
||||
headers: {
|
||||
'X-Datasource-Uid': 'abc',
|
||||
'X-Plugin-Id': 'dummy',
|
||||
},
|
||||
method: 'GET',
|
||||
url: '/api/datasources/uid/abc/health',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function createMockDatasource() {
|
||||
|
@ -282,7 +282,7 @@ class DataSourceWithBackend<
|
||||
method: 'GET',
|
||||
headers: options?.headers ? { ...options.headers, ...headers } : headers,
|
||||
params: params ?? options?.params,
|
||||
url: `/api/datasources/${this.id}/resources/${path}`,
|
||||
url: `/api/datasources/uid/${this.uid}/resources/${path}`,
|
||||
})
|
||||
);
|
||||
return result.data;
|
||||
@ -303,7 +303,7 @@ class DataSourceWithBackend<
|
||||
method: 'POST',
|
||||
headers: options?.headers ? { ...options.headers, ...headers } : headers,
|
||||
data: data ?? { ...data },
|
||||
url: `/api/datasources/${this.id}/resources/${path}`,
|
||||
url: `/api/datasources/uid/${this.uid}/resources/${path}`,
|
||||
})
|
||||
);
|
||||
return result.data;
|
||||
@ -316,7 +316,7 @@ class DataSourceWithBackend<
|
||||
return lastValueFrom(
|
||||
getBackendSrv().fetch<HealthCheckResult>({
|
||||
method: 'GET',
|
||||
url: `/api/datasources/${this.id}/health`,
|
||||
url: `/api/datasources/uid/${this.uid}/health`,
|
||||
showErrorAlert: false,
|
||||
headers: this.getRequestHeaders(),
|
||||
})
|
||||
|
@ -133,7 +133,7 @@ export class DashboardLoaderSrv {
|
||||
});
|
||||
|
||||
return getBackendSrv()
|
||||
.get(`/api/datasources/${ds.id}/resources/${path}`, queryParams)
|
||||
.get(`/api/datasources/uid/${ds.uid}/resources/${path}`, queryParams)
|
||||
.then((data) => {
|
||||
return {
|
||||
meta: {
|
||||
|
Loading…
Reference in New Issue
Block a user