mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-13 01:20:24 +02:00
add tests
This commit is contained in:
@ -14,6 +14,24 @@ class MyTests(unittest.TestCase):
|
|||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat.out'), 'r') as f:
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat.out'), 'r') as f:
|
||||||
self.ubuntu_18_4_netstat = f.read()
|
self.ubuntu_18_4_netstat = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-l.out'), 'r') as f:
|
||||||
|
self.centos_7_7_netstat_l = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-l.out'), 'r') as f:
|
||||||
|
self.ubuntu_18_4_netstat_l = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-p.out'), 'r') as f:
|
||||||
|
self.centos_7_7_netstat_p = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-p.out'), 'r') as f:
|
||||||
|
self.ubuntu_18_4_netstat_p = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-sudo-lnp.out'), 'r') as f:
|
||||||
|
self.centos_7_7_netstat_sudo_lnp = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-sudo-lnp.out'), 'r') as f:
|
||||||
|
self.ubuntu_18_4_netstat_sudo_lnp = f.read()
|
||||||
|
|
||||||
def test_netstat_centos_7_7(self):
|
def test_netstat_centos_7_7(self):
|
||||||
"""
|
"""
|
||||||
Test 'netstat' on Centos 7.7
|
Test 'netstat' on Centos 7.7
|
||||||
@ -42,6 +60,93 @@ class MyTests(unittest.TestCase):
|
|||||||
'receive_q': '0',
|
'receive_q': '0',
|
||||||
'send_q': '0'})
|
'send_q': '0'})
|
||||||
|
|
||||||
|
def test_netstat_l_centos_7_7(self):
|
||||||
|
"""
|
||||||
|
Test 'netstat -l' on Centos 7.7
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.netstat.parse(self.centos_7_7_netstat_l)[3], {'transport_protocol': 'tcp',
|
||||||
|
'network_protocol': 'ipv6',
|
||||||
|
'local_address': '[::]',
|
||||||
|
'local_port': 'ssh',
|
||||||
|
'foreign_address': '[::]',
|
||||||
|
'foreign_port': '*',
|
||||||
|
'state': 'LISTEN',
|
||||||
|
'receive_q': '0',
|
||||||
|
'send_q': '0'})
|
||||||
|
|
||||||
|
def test_netstat_l_ubuntu_18_4(self):
|
||||||
|
"""
|
||||||
|
Test 'netstat -l' on Ubuntu 18.4
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_l)[4], {'transport_protocol': 'udp',
|
||||||
|
'network_protocol': 'ipv4',
|
||||||
|
'local_address': 'localhost',
|
||||||
|
'local_port': 'domain',
|
||||||
|
'foreign_address': '0.0.0.0',
|
||||||
|
'foreign_port': '*',
|
||||||
|
'receive_q': '0',
|
||||||
|
'send_q': '0'})
|
||||||
|
|
||||||
|
def test_netstat_p_centos_7_7(self):
|
||||||
|
"""
|
||||||
|
Test 'netstat -l' on Centos 7.7
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.netstat.parse(self.centos_7_7_netstat_p), [{'transport_protocol': 'tcp',
|
||||||
|
'network_protocol': 'ipv4',
|
||||||
|
'local_address': 'localhost.localdoma',
|
||||||
|
'local_port': 'ssh',
|
||||||
|
'foreign_address': '192.168.71.1',
|
||||||
|
'foreign_port': '58727',
|
||||||
|
'state': 'ESTABLISHED',
|
||||||
|
'receive_q': '0',
|
||||||
|
'send_q': '0'}])
|
||||||
|
|
||||||
|
def test_netstat_p_ubuntu_18_4(self):
|
||||||
|
"""
|
||||||
|
Test 'netstat -l' on Ubuntu 18.4
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_p)[1], {'transport_protocol': 'tcp',
|
||||||
|
'network_protocol': 'ipv4',
|
||||||
|
'local_address': 'kbrazil-ubuntu',
|
||||||
|
'local_port': '55656',
|
||||||
|
'foreign_address': 'lb-192-30-253-113',
|
||||||
|
'foreign_port': 'https',
|
||||||
|
'state': 'ESTABLISHED',
|
||||||
|
'pid': '23921',
|
||||||
|
'program_name': 'git-remote-ht',
|
||||||
|
'receive_q': '0',
|
||||||
|
'send_q': '0'})
|
||||||
|
|
||||||
|
def test_netstat_sudo_lnp_centos_7_7(self):
|
||||||
|
"""
|
||||||
|
Test 'sudo netstat -lnp' on Centos 7.7
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.netstat.parse(self.centos_7_7_netstat_sudo_lnp)[5], {'transport_protocol': 'udp',
|
||||||
|
'network_protocol': 'ipv4',
|
||||||
|
'local_address': '127.0.0.1',
|
||||||
|
'local_port': '323',
|
||||||
|
'foreign_address': '0.0.0.0',
|
||||||
|
'foreign_port': '*',
|
||||||
|
'pid': '795',
|
||||||
|
'program_name': 'chronyd',
|
||||||
|
'receive_q': '0',
|
||||||
|
'send_q': '0'})
|
||||||
|
|
||||||
|
def test_netstat_sudo_lnp_ubuntu_18_4(self):
|
||||||
|
"""
|
||||||
|
Test 'sudo netstat -lnp' on Ubuntu 18.4
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_sudo_lnp)[4], {'transport_protocol': 'udp',
|
||||||
|
'network_protocol': 'ipv4',
|
||||||
|
'local_address': '127.0.0.53',
|
||||||
|
'local_port': '53',
|
||||||
|
'foreign_address': '0.0.0.0',
|
||||||
|
'foreign_port': '*',
|
||||||
|
'pid': '885',
|
||||||
|
'program_name': 'systemd-resolve',
|
||||||
|
'receive_q': '0',
|
||||||
|
'send_q': '0'})
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
83
tests/test_ps.py
Normal file
83
tests/test_ps.py
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
import jc.parsers.ps
|
||||||
|
|
||||||
|
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
|
||||||
|
class MyTests(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ps-ef.out'), 'r') as f:
|
||||||
|
self.centos_7_7_ps_ef = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ps-ef.out'), 'r') as f:
|
||||||
|
self.ubuntu_18_4_ps_ef = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ps-axu.out'), 'r') as f:
|
||||||
|
self.centos_7_7_ps_axu = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ps-axu.out'), 'r') as f:
|
||||||
|
self.ubuntu_18_4_ps_axu = f.read()
|
||||||
|
|
||||||
|
def test_ps_ef_centos_7_7(self):
|
||||||
|
"""
|
||||||
|
Test 'ps -ef' on Centos 7.7
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.ps.parse(self.centos_7_7_ps_ef)[25], {'uid': 'root',
|
||||||
|
'pid': '33',
|
||||||
|
'ppid': '2',
|
||||||
|
'c': '0',
|
||||||
|
'stime': 'Oct25',
|
||||||
|
'tty': '?',
|
||||||
|
'time': '00:00:00',
|
||||||
|
'cmd': '[crypto]'})
|
||||||
|
|
||||||
|
def test_ps_ef_ubuntu_18_4(self):
|
||||||
|
"""
|
||||||
|
Test 'ps -ef' on Ubuntu 18.4
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.ps.parse(self.ubuntu_18_4_ps_ef)[30], {'uid': 'root',
|
||||||
|
'pid': '36',
|
||||||
|
'ppid': '2',
|
||||||
|
'c': '0',
|
||||||
|
'stime': 'Oct26',
|
||||||
|
'tty': '?',
|
||||||
|
'time': '00:00:00',
|
||||||
|
'cmd': '[ecryptfs-kthrea]'})
|
||||||
|
|
||||||
|
def test_ps_axu_centos_7_7(self):
|
||||||
|
"""
|
||||||
|
Test 'ps axu' on Centos 7.7
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.ps.parse(self.centos_7_7_ps_axu)[13], {'user': 'root',
|
||||||
|
'pid': '16',
|
||||||
|
'cpu_percent': '0.0',
|
||||||
|
'mem_percent': '0.0',
|
||||||
|
'vsz': '0',
|
||||||
|
'rss': '0',
|
||||||
|
'tty': '?',
|
||||||
|
'stat': 'S<',
|
||||||
|
'start': 'Oct25',
|
||||||
|
'time': '0:00',
|
||||||
|
'command': '[writeback]'})
|
||||||
|
|
||||||
|
def test_ps_axu_ubuntu_18_4(self):
|
||||||
|
"""
|
||||||
|
Test 'ps axu' on Ubuntu 18.4
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.ps.parse(self.ubuntu_18_4_ps_axu)[40], {'user': 'root',
|
||||||
|
'pid': '170',
|
||||||
|
'cpu_percent': '0.0',
|
||||||
|
'mem_percent': '0.0',
|
||||||
|
'vsz': '0',
|
||||||
|
'rss': '0',
|
||||||
|
'tty': '?',
|
||||||
|
'stat': 'I<',
|
||||||
|
'start': 'Oct26',
|
||||||
|
'time': '0:00',
|
||||||
|
'command': '[mpt_poll_0]'})
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
77
tests/test_route.py
Normal file
77
tests/test_route.py
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
import jc.parsers.route
|
||||||
|
|
||||||
|
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
|
||||||
|
class MyTests(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/route.out'), 'r') as f:
|
||||||
|
self.centos_7_7_route = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/route.out'), 'r') as f:
|
||||||
|
self.ubuntu_18_4_route = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/route-vn.out'), 'r') as f:
|
||||||
|
self.centos_7_7_route_vn = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/route-vn.out'), 'r') as f:
|
||||||
|
self.ubuntu_18_4_route_vn = f.read()
|
||||||
|
|
||||||
|
def test_route_centos_7_7(self):
|
||||||
|
"""
|
||||||
|
Test 'route' on Centos 7.7
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.route.parse(self.centos_7_7_route)[2], {'destination': '192.168.71.0',
|
||||||
|
'gateway': '0.0.0.0',
|
||||||
|
'genmask': '255.255.255.0',
|
||||||
|
'flags': 'U',
|
||||||
|
'metric': '100',
|
||||||
|
'ref': '0',
|
||||||
|
'use': '0',
|
||||||
|
'iface': 'ens33'})
|
||||||
|
|
||||||
|
def test_route_ubuntu_18_4(self):
|
||||||
|
"""
|
||||||
|
Test 'route' on Ubuntu 18.4
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.route.parse(self.ubuntu_18_4_route)[1], {'destination': '192.168.71.0',
|
||||||
|
'gateway': '0.0.0.0',
|
||||||
|
'genmask': '255.255.255.0',
|
||||||
|
'flags': 'U',
|
||||||
|
'metric': '0',
|
||||||
|
'ref': '0',
|
||||||
|
'use': '0',
|
||||||
|
'iface': 'ens33'})
|
||||||
|
|
||||||
|
def test_route_vn_centos_7_7(self):
|
||||||
|
"""
|
||||||
|
Test 'route -vn' on Centos 7.7
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.route.parse(self.centos_7_7_route_vn)[2], {'destination': '192.168.71.0',
|
||||||
|
'gateway': '0.0.0.0',
|
||||||
|
'genmask': '255.255.255.0',
|
||||||
|
'flags': 'U',
|
||||||
|
'metric': '100',
|
||||||
|
'ref': '0',
|
||||||
|
'use': '0',
|
||||||
|
'iface': 'ens33'})
|
||||||
|
|
||||||
|
def test_route_vn_ubuntu_18_4(self):
|
||||||
|
"""
|
||||||
|
Test 'route -vn' on Ubuntu 18.4
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.route.parse(self.ubuntu_18_4_route_vn)[2], {'destination': '192.168.71.2',
|
||||||
|
'gateway': '0.0.0.0',
|
||||||
|
'genmask': '255.255.255.255',
|
||||||
|
'flags': 'UH',
|
||||||
|
'metric': '100',
|
||||||
|
'ref': '0',
|
||||||
|
'use': '0',
|
||||||
|
'iface': 'ens33'})
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Reference in New Issue
Block a user