Commit 6670acd0 by Tobias Skarhed

Remove irrelevant tests and templateSrv stub

parent 74bf8096
......@@ -404,6 +404,7 @@ export default class CloudWatchDatasource {
}
expandTemplateVariable(targets, scopedVars, templateSrv) {
// Datasource and template srv logic uber-complected. This should be cleaned up.
return _.chain(targets)
.map(target => {
var dimensionKey = _.findKey(target.dimensions, v => {
......
import '../datasource';
import { TemplateSrvStub } from 'test/specs/helpers';
import CloudWatchDatasource from '../datasource';
import 'app/features/dashboard/time_srv';
import * as dateMath from 'app/core/utils/datemath';
import _ from 'lodash';
describe('CloudWatchDatasource', function() {
let instanceSettings = {
jsonData: { defaultRegion: 'us-east-1', access: 'proxy' },
};
let templateSrv = new TemplateSrvStub();
let templateSrv = {
templateSettings: { interpolate: /\[\[([\s\S]+?)\]\]/g },
replace: jest.fn(text => _.template(text, templateSrv.templateSettings)(templateSrv.data)),
variableExists: jest.fn(() => false),
};
let timeSrv = {
time: { from: 'now-1h', to: 'now' },
......@@ -68,8 +73,8 @@ describe('CloudWatchDatasource', function() {
},
};
beforeEach(async () => {
ctx.backendSrv.datasourceRequest = await jest.fn(params => {
beforeEach(() => {
ctx.backendSrv.datasourceRequest = jest.fn(params => {
requestParams = params.data;
return Promise.resolve({ data: response });
});
......@@ -123,103 +128,6 @@ describe('CloudWatchDatasource', function() {
done();
});
});
it('should generate the correct targets by expanding template variables', function() {
var templateSrv = {
variables: [
{
name: 'instance_id',
options: [
{ text: 'i-23456789', value: 'i-23456789', selected: false },
{ text: 'i-34567890', value: 'i-34567890', selected: true },
],
current: {
text: 'i-34567890',
value: 'i-34567890',
},
},
],
replace: function(target, scopedVars) {
if (target === '$instance_id' && scopedVars['instance_id']['text'] === 'i-34567890') {
return 'i-34567890';
} else {
return '';
}
},
getVariableName: function(e) {
return 'instance_id';
},
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).toBe('i-34567890');
});
it('should generate the correct targets by expanding template variables from url', function() {
var templateSrv = {
variables: [
{
name: 'instance_id',
options: [
{ text: 'i-23456789', value: 'i-23456789', selected: false },
{ text: 'i-34567890', value: 'i-34567890', selected: false },
],
current: 'i-45678901',
},
],
replace: function(target, scopedVars) {
if (target === '$instance_id') {
return 'i-45678901';
} else {
return '';
}
},
getVariableName: function(e) {
return 'instance_id';
},
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).toBe('i-45678901');
});
});
describe('When query region is "default"', function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment