mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Remove irrelevant tests and templateSrv stub
This commit is contained in:
parent
74bf80962d
commit
6670acd082
@ -404,6 +404,7 @@ export default class CloudWatchDatasource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expandTemplateVariable(targets, scopedVars, templateSrv) {
|
expandTemplateVariable(targets, scopedVars, templateSrv) {
|
||||||
|
// Datasource and template srv logic uber-complected. This should be cleaned up.
|
||||||
return _.chain(targets)
|
return _.chain(targets)
|
||||||
.map(target => {
|
.map(target => {
|
||||||
var dimensionKey = _.findKey(target.dimensions, v => {
|
var dimensionKey = _.findKey(target.dimensions, v => {
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
import '../datasource';
|
import '../datasource';
|
||||||
import { TemplateSrvStub } from 'test/specs/helpers';
|
|
||||||
import CloudWatchDatasource from '../datasource';
|
import CloudWatchDatasource from '../datasource';
|
||||||
import 'app/features/dashboard/time_srv';
|
import 'app/features/dashboard/time_srv';
|
||||||
import * as dateMath from 'app/core/utils/datemath';
|
import * as dateMath from 'app/core/utils/datemath';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
describe('CloudWatchDatasource', function() {
|
describe('CloudWatchDatasource', function() {
|
||||||
let instanceSettings = {
|
let instanceSettings = {
|
||||||
jsonData: { defaultRegion: 'us-east-1', access: 'proxy' },
|
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 = {
|
let timeSrv = {
|
||||||
time: { from: 'now-1h', to: 'now' },
|
time: { from: 'now-1h', to: 'now' },
|
||||||
@ -68,8 +73,8 @@ describe('CloudWatchDatasource', function() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(() => {
|
||||||
ctx.backendSrv.datasourceRequest = await jest.fn(params => {
|
ctx.backendSrv.datasourceRequest = jest.fn(params => {
|
||||||
requestParams = params.data;
|
requestParams = params.data;
|
||||||
return Promise.resolve({ data: response });
|
return Promise.resolve({ data: response });
|
||||||
});
|
});
|
||||||
@ -123,103 +128,6 @@ describe('CloudWatchDatasource', function() {
|
|||||||
done();
|
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() {
|
describe('When query region is "default"', function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user