diff --git a/public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts b/public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts index 86e085b3f6f..0b9b3b53fb6 100644 --- a/public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts +++ b/public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts @@ -98,6 +98,38 @@ describe('CloudWatchDatasource', function() { }); ctx.$rootScope.$apply(); }); + + it('should generate the correct targets by expanding template variables', function() { + var templateSrv = { + variables: [ + { + name: 'instance_id', + options: [ + { value: 'i-23456789', selected: false }, + { value: 'i-34567890', selected: true } + ] + } + ], + variableExists: function (e) { return true; }, + containsVariable: function (str, variableName) { return str.indexOf('$' + variableName) !== -1; } + }; + + var targets = [ + { + region: 'us-east-1', + namespace: 'AWS/EC2', + metricName: 'CPUUtilization', + dimensions: { + InstanceId: '$instance_id' + }, + statistics: ['Average'], + period: 300 + } + ]; + + var result = ctx.ds.expandTemplateVariable(targets, templateSrv); + expect(result[0].dimensions.InstanceId).to.be('i-34567890'); + }); }); function describeMetricFindQuery(query, func) {