From f38349074971c5a8ea81261a24817ac2901933f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Bedi?= Date: Thu, 13 Jun 2024 16:18:20 +0200 Subject: [PATCH] Add tests --- .../zabbix_api/zabbixAPIConnector.test.ts | 21 +++++++++++++++++++ .../zabbix_api/zabbixAPIConnector.ts | 5 ++++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.test.ts diff --git a/src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.test.ts b/src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.test.ts new file mode 100644 index 00000000..343df2b4 --- /dev/null +++ b/src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.test.ts @@ -0,0 +1,21 @@ +import { ZabbixAPIConnector } from './zabbixAPIConnector'; + +describe('Zabbix API connector', () => { + describe('getProxies function', () => { + it('should send the name parameter to the request when version is 7 or greater for the getProxies', async () => { + const zabbixAPIConnector = new ZabbixAPIConnector(true, true, 123, '7.0.0'); + zabbixAPIConnector.request = jest.fn(); + + await zabbixAPIConnector.getProxies(); + expect(zabbixAPIConnector.request).toHaveBeenCalledWith('proxy.get', { output: ['proxyid', 'name'] }); + }); + + it('should send the host parameter when version is less than 7.0.0', () => { + const zabbixAPIConnector = new ZabbixAPIConnector(true, true, 123, '6.0.0'); + zabbixAPIConnector.request = jest.fn(); + + zabbixAPIConnector.getProxies(); + expect(zabbixAPIConnector.request).toHaveBeenCalledWith('proxy.get', { output: ['proxyid', 'host'] }); + }); + }); +}); diff --git a/src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.ts b/src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.ts index 9a0b8598..5ded01ba 100644 --- a/src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.ts +++ b/src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.ts @@ -28,7 +28,7 @@ export class ZabbixAPIConnector { getVersionPromise: Promise; datasourceId: number; - constructor(basicAuth: any, withCredentials: boolean, datasourceId: number) { + constructor(basicAuth: any, withCredentials: boolean, datasourceId: number, zabbixVersion?: string) { this.datasourceId = datasourceId; this.backendAPIUrl = `/api/datasources/${this.datasourceId}/resources/zabbix-api`; @@ -37,6 +37,8 @@ export class ZabbixAPIConnector { withCredentials: withCredentials, }; + this.version = zabbixVersion || null; + this.getTrend = this.getTrend_ZBXNEXT1193; //getTrend = getTrend_30; @@ -877,6 +879,7 @@ export class ZabbixAPIConnector { const params = { output: ['proxyid'], }; + // Before version 7.0.0 host was used, after - name if (semver.lt(this.version, '7.0.0')) { params.output.push('host'); } else {