Skip to content
This repository was archived by the owner on Dec 17, 2021. It is now read-only.

Commit 9648d7e

Browse files
authored
feat: added unit tests (#37)
1 parent 7a6eb51 commit 9648d7e

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

splunk_connect_for_snmp_poller/manager/task_utilities.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def get_translated_string(mib_server_url, varBinds):
6363
f"Exception occurred while logging varBinds name & value. Exception: {e}"
6464
)
6565

66-
# Overrid the varBinds string with translated varBinds string
66+
# Override the varBinds string with translated varBinds string
6767
try:
6868
result = get_translation(varBinds, mib_server_url, metric)
6969
logger.info(f"=========result=======\n{result}")
@@ -90,7 +90,7 @@ def mib_string_handler(
9090
"""
9191
Perform the SNMP Get for mib-name/string,
9292
e.g. ['SNMPv2-MIB', 'sysUpTime',0] (syntax -> [<mib_file_name>, <mib_name/string>, <min_index>])
93-
which querise the info correalted to this specific mib-name/string (e.g. sysUpTime)
93+
which queries the info correlated to this specific mib-name/string (e.g. sysUpTime)
9494
"""
9595
logger.info(
9696
f"Executing get_by_mib_name() with {host} {port} {version} {community} {mib_file} {mib_name} {mib_index} {mib_server_url}"
@@ -169,7 +169,7 @@ def walk_handler(snmp_engine, community, host, port, profile, mib_server_url, re
169169
"""
170170
Perform the SNMP Walk for oid end with *,
171171
e.g. 1.3.6.1.2.1.1.9.*,
172-
which queries the infos correalted to all the oids that underneath the prefix before the *, e.g. 1.3.6.1.2.1.1.9
172+
which queries the infos correlated to all the oids that underneath the prefix before the *, e.g. 1.3.6.1.2.1.1.9
173173
"""
174174
for (errorIndication, errorStatus, errorIndex, varBinds) in nextCmd(
175175
snmp_engine,

tests/test_task_utilities.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from unittest import TestCase
2+
3+
from splunk_connect_for_snmp_poller.manager.task_utilities import is_metric_data, parse_port
4+
5+
6+
class ObjectTypeMock:
7+
8+
def __init__(self, value):
9+
self._value = value
10+
11+
def prettyPrint(self):
12+
return self._value
13+
14+
15+
class TestTaskUtilities(TestCase):
16+
def test_metric_for_integer(self):
17+
self.assertTrue(is_metric_data([('some_name', ObjectTypeMock('1'))]))
18+
19+
def test_metric_for_negative_integer(self):
20+
self.assertTrue(is_metric_data([('some_name', ObjectTypeMock('-5'))]))
21+
22+
def test_metric_for_float(self):
23+
self.assertTrue(is_metric_data([('some_name', ObjectTypeMock('2.0'))]))
24+
25+
def test_metric_for_negative_float(self):
26+
self.assertTrue(is_metric_data([('some_name', ObjectTypeMock('-2.0'))]))
27+
28+
def test_metric_for_zero(self):
29+
self.assertTrue(is_metric_data([('some_name', ObjectTypeMock('0'))]))
30+
31+
def test_metric_for_string(self):
32+
self.assertFalse(is_metric_data([('some_name', ObjectTypeMock('asdad'))]))
33+
34+
def test_port_parse_with_default_port(self):
35+
host, port = parse_port('192.168.0.13')
36+
self.assertEqual(host, '192.168.0.13')
37+
self.assertEqual(port, 161)
38+
39+
def test_port_parse_with_specified_port(self):
40+
host, port = parse_port('192.168.0.13:765')
41+
self.assertEqual(host, '192.168.0.13')
42+
self.assertEqual(port, '765')
43+

0 commit comments

Comments
 (0)