mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
Fix unexpected error when creating a new cloudwatch datasource. Involves a fair amount of refactoring, so if this causes unexpected issues related to region fetching we can turn this off with the cloudwatchNewRegionsHandler feature toggle, although we do not predict it will so we are enabling it to default to true and hope to remove it shortly.
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { getBackendSrv, setBackendSrv } from '@grafana/runtime';
|
|
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
|
import { TemplateSrv } from 'app/features/templating/template_srv';
|
|
import { CustomVariableModel } from 'app/features/variables/types';
|
|
|
|
import { ResourcesAPI } from '../resources/ResourcesAPI';
|
|
|
|
import { CloudWatchSettings, setupMockedTemplateService } from './CloudWatchDataSource';
|
|
|
|
export function setupMockedResourcesAPI({
|
|
variables,
|
|
response,
|
|
getMock,
|
|
}: {
|
|
getMock?: jest.Mock;
|
|
response?: unknown;
|
|
variables?: CustomVariableModel[];
|
|
mockGetVariableName?: boolean;
|
|
} = {}) {
|
|
let templateService = variables ? setupMockedTemplateService(variables) : new TemplateSrv();
|
|
|
|
const timeSrv = getTimeSrv();
|
|
const api = new ResourcesAPI(CloudWatchSettings, templateService);
|
|
let resourceRequestMock = getMock ? getMock : jest.fn().mockReturnValue(response);
|
|
setBackendSrv({
|
|
...getBackendSrv(),
|
|
get: resourceRequestMock,
|
|
});
|
|
|
|
return { api, resourceRequestMock, templateService, timeSrv };
|
|
}
|