fix datasource tests
This commit is contained in:
@@ -12,10 +12,8 @@ import { ZabbixAPIError } from './zabbix/connectors/zabbix_api/zabbixAPICore';
|
|||||||
export class ZabbixDatasource {
|
export class ZabbixDatasource {
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor(instanceSettings, templateSrv, alertSrv, dashboardSrv, backendSrv, datasourceSrv, zabbixAlertingSrv) {
|
constructor(instanceSettings, templateSrv, backendSrv, datasourceSrv, zabbixAlertingSrv) {
|
||||||
this.templateSrv = templateSrv;
|
this.templateSrv = templateSrv;
|
||||||
this.alertSrv = alertSrv;
|
|
||||||
this.dashboardSrv = dashboardSrv;
|
|
||||||
this.zabbixAlertingSrv = zabbixAlertingSrv;
|
this.zabbixAlertingSrv = zabbixAlertingSrv;
|
||||||
|
|
||||||
// Use custom format for template variables
|
// Use custom format for template variables
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import Q, { Promise } from "q";
|
|
||||||
import { Datasource } from "../module";
|
import { Datasource } from "../module";
|
||||||
import { zabbixTemplateFormat } from "../datasource";
|
import { zabbixTemplateFormat } from "../datasource";
|
||||||
|
|
||||||
@@ -9,7 +8,7 @@ describe('ZabbixDatasource', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ctx.instanceSettings = {
|
ctx.instanceSettings = {
|
||||||
jsonData: {
|
jsonData: {
|
||||||
alerting: true,
|
alerting: false,
|
||||||
username: 'zabbix',
|
username: 'zabbix',
|
||||||
password: 'zabbix',
|
password: 'zabbix',
|
||||||
trends: true,
|
trends: true,
|
||||||
@@ -21,21 +20,21 @@ describe('ZabbixDatasource', () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
ctx.templateSrv = {};
|
ctx.templateSrv = {};
|
||||||
ctx.alertSrv = {};
|
ctx.backendSrv = {
|
||||||
ctx.dashboardSrv = {};
|
datasourceRequest: jest.fn()
|
||||||
|
};
|
||||||
|
ctx.datasourceSrv = {};
|
||||||
ctx.zabbixAlertingSrv = {
|
ctx.zabbixAlertingSrv = {
|
||||||
setPanelAlertState: jest.fn(),
|
setPanelAlertState: jest.fn(),
|
||||||
removeZabbixThreshold: jest.fn(),
|
removeZabbixThreshold: jest.fn(),
|
||||||
};
|
};
|
||||||
ctx.zabbix = () => {};
|
|
||||||
|
|
||||||
ctx.ds = new Datasource(ctx.instanceSettings, ctx.templateSrv, ctx.alertSrv, ctx.dashboardSrv, ctx.zabbixAlertingSrv, ctx.zabbix);
|
ctx.ds = new Datasource(ctx.instanceSettings, ctx.templateSrv, ctx.backendSrv, ctx.datasourceSrv, ctx.zabbixAlertingSrv);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('When querying data', () => {
|
describe('When querying data', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ctx.ds.replaceTemplateVars = (str) => str;
|
ctx.ds.replaceTemplateVars = (str) => str;
|
||||||
ctx.ds.alertQuery = () => Q.when([]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.options = {
|
ctx.options = {
|
||||||
@@ -99,8 +98,7 @@ describe('ZabbixDatasource', () => {
|
|||||||
describe('When querying text data', () => {
|
describe('When querying text data', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ctx.ds.replaceTemplateVars = (str) => str;
|
ctx.ds.replaceTemplateVars = (str) => str;
|
||||||
ctx.ds.alertQuery = () => Q.when([]);
|
ctx.ds.zabbix.zabbixAPI.getHistory = jest.fn().mockReturnValue(Promise.resolve([
|
||||||
ctx.ds.zabbix.getHistory = jest.fn().mockReturnValue(Promise.resolve([
|
|
||||||
{clock: "1500010200", itemid:"10100", ns:"900111000", value:"Linux first"},
|
{clock: "1500010200", itemid:"10100", ns:"900111000", value:"Linux first"},
|
||||||
{clock: "1500010300", itemid:"10100", ns:"900111000", value:"Linux 2nd"},
|
{clock: "1500010300", itemid:"10100", ns:"900111000", value:"Linux 2nd"},
|
||||||
{clock: "1500010400", itemid:"10100", ns:"900111000", value:"Linux last"}
|
{clock: "1500010400", itemid:"10100", ns:"900111000", value:"Linux last"}
|
||||||
@@ -243,10 +241,10 @@ describe('ZabbixDatasource', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ctx.ds.replaceTemplateVars = (str) => str;
|
ctx.ds.replaceTemplateVars = (str) => str;
|
||||||
ctx.ds.zabbix = {
|
ctx.ds.zabbix = {
|
||||||
getGroups: jest.fn().mockReturnValue(Q.when([])),
|
getGroups: jest.fn().mockReturnValue(Promise.resolve([])),
|
||||||
getHosts: jest.fn().mockReturnValue(Q.when([])),
|
getHosts: jest.fn().mockReturnValue(Promise.resolve([])),
|
||||||
getApps: jest.fn().mockReturnValue(Q.when([])),
|
getApps: jest.fn().mockReturnValue(Promise.resolve([])),
|
||||||
getItems: jest.fn().mockReturnValue(Q.when([]))
|
getItems: jest.fn().mockReturnValue(Promise.resolve([]))
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -341,7 +339,7 @@ describe('ZabbixDatasource', () => {
|
|||||||
"hosts": [{"hostid": "10631", "name": "Test host"}],
|
"hosts": [{"hostid": "10631", "name": "Test host"}],
|
||||||
"item": "Test item"
|
"item": "Test item"
|
||||||
}];
|
}];
|
||||||
ctx.ds.zabbix.getItemsFromTarget = () => Promise.resolve(targetItems);
|
ctx.ds.zabbix.getItemsFromTarget = jest.fn().mockReturnValue(Promise.resolve(targetItems));
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
"panelId": 10,
|
"panelId": 10,
|
||||||
@@ -362,7 +360,7 @@ describe('ZabbixDatasource', () => {
|
|||||||
"expression": "{15915}<100",
|
"expression": "{15915}<100",
|
||||||
}];
|
}];
|
||||||
|
|
||||||
ctx.ds.zabbix.getAlerts = () => Promise.resolve(itemTriggers);
|
ctx.ds.zabbix.getAlerts = jest.fn().mockReturnValue(Promise.resolve(itemTriggers));
|
||||||
|
|
||||||
return ctx.ds.alertQuery(options)
|
return ctx.ds.alertQuery(options)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
@@ -380,7 +378,7 @@ describe('ZabbixDatasource', () => {
|
|||||||
"expression": "{15915}<=100",
|
"expression": "{15915}<=100",
|
||||||
}];
|
}];
|
||||||
|
|
||||||
ctx.ds.zabbix.getAlerts = () => Promise.resolve(itemTriggers);
|
ctx.ds.zabbix.getAlerts = jest.fn().mockReturnValue(Promise.resolve(itemTriggers));
|
||||||
|
|
||||||
return ctx.ds.alertQuery(options)
|
return ctx.ds.alertQuery(options)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
@@ -398,7 +396,7 @@ describe('ZabbixDatasource', () => {
|
|||||||
"expression": "{15915}>=30",
|
"expression": "{15915}>=30",
|
||||||
}];
|
}];
|
||||||
|
|
||||||
ctx.ds.zabbix.getAlerts = () => Promise.resolve(itemTriggers);
|
ctx.ds.zabbix.getAlerts = jest.fn().mockReturnValue(Promise.resolve(itemTriggers));
|
||||||
|
|
||||||
return ctx.ds.alertQuery(options)
|
return ctx.ds.alertQuery(options)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
@@ -416,7 +414,7 @@ describe('ZabbixDatasource', () => {
|
|||||||
"expression": "{15915}=50",
|
"expression": "{15915}=50",
|
||||||
}];
|
}];
|
||||||
|
|
||||||
ctx.ds.zabbix.getAlerts = () => Promise.resolve(itemTriggers);
|
ctx.ds.zabbix.getAlerts = jest.fn().mockReturnValue(Promise.resolve(itemTriggers));
|
||||||
|
|
||||||
return ctx.ds.alertQuery(options)
|
return ctx.ds.alertQuery(options)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
|
|||||||
Reference in New Issue
Block a user