mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
CloudWatch: Region template query fix (#20661)
* Make region an optional parameter * Test region template query
This commit is contained in:
parent
49dfb9a5d3
commit
116b6188a6
@ -334,8 +334,8 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery,
|
||||
return this.doMetricQueryRequest('namespaces', null);
|
||||
}
|
||||
|
||||
async getMetrics(namespace: string, region: string) {
|
||||
if (!namespace || !region) {
|
||||
async getMetrics(namespace: string, region?: string) {
|
||||
if (!namespace) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
@ -307,6 +307,39 @@ describe('CloudWatchDatasource', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when regions query is used', () => {
|
||||
beforeEach(() => {
|
||||
ctx.backendSrv.datasourceRequest = jest.fn(() => {
|
||||
return Promise.resolve({});
|
||||
});
|
||||
ctx.ds = new CloudWatchDatasource(instanceSettings, {} as any, backendSrv, templateSrv, timeSrv);
|
||||
ctx.ds.doMetricQueryRequest = jest.fn(() => []);
|
||||
});
|
||||
describe('and region param is left out', () => {
|
||||
it('should use the default region', done => {
|
||||
ctx.ds.metricFindQuery('metrics(testNamespace)').then(() => {
|
||||
expect(ctx.ds.doMetricQueryRequest).toHaveBeenCalledWith('metrics', {
|
||||
namespace: 'testNamespace',
|
||||
region: instanceSettings.jsonData.defaultRegion,
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('and region param is defined by user', () => {
|
||||
it('should use the user defined region', done => {
|
||||
ctx.ds.metricFindQuery('metrics(testNamespace2, custom-region)').then(() => {
|
||||
expect(ctx.ds.doMetricQueryRequest).toHaveBeenCalledWith('metrics', {
|
||||
namespace: 'testNamespace2',
|
||||
region: 'custom-region',
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('When query region is "default"', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user