Refactor: Use data source UID rather than ID (#62781)

This commit is contained in:
Andres Martinez Gotor 2023-02-06 11:12:44 +01:00 committed by GitHub
parent 8f96fe5ae9
commit 9893408af9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 4 deletions

View File

@ -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() {

View File

@ -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(),
})

View File

@ -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: {