From e3db87d27a11edc4dd4aafbdd7472099cfc59bcd Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Wed, 27 Nov 2019 17:06:11 +0100 Subject: [PATCH] CloudWatch: Region template query fix (#20661) * Make region an optional parameter * Test region template query (cherry picked from commit 116b6188a6a34e84cd38ce2b44d90b222af49a59) --- .../datasource/cloudwatch/datasource.ts | 4 +-- .../cloudwatch/specs/datasource.test.ts | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/cloudwatch/datasource.ts b/public/app/plugins/datasource/cloudwatch/datasource.ts index ce9b11af910..5fe443e780c 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.ts +++ b/public/app/plugins/datasource/cloudwatch/datasource.ts @@ -334,8 +334,8 @@ export default class CloudWatchDatasource extends DataSourceApi { }); }); }); + + 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"', () => {