1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-08-06 22:32:54 +02:00

add linux netstat -r tests

This commit is contained in:
Kelly Brazil
2020-05-22 12:44:51 -07:00
parent ec2cd2d708
commit 2ca1587a49
10 changed files with 102 additions and 0 deletions

View File

@ -9,7 +9,11 @@ THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
def setUp(self):
#
# input
#
# netstat
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_netstat = f.read()
@ -52,6 +56,24 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-Abn.out'), 'r', encoding='utf-8') as f:
self.osx_14_6_netstat_Abn = f.read()
# netstat -r
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-r.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_netstat_r = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-rne.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_netstat_rne = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-rnee.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_netstat_rnee = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-r.out'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_netstat_r = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-rne.out'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_netstat_rne = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-rnee.out'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_netstat_rnee = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-r.out'), 'r', encoding='utf-8') as f:
self.osx_14_6_netstat_r = f.read()
@ -59,7 +81,11 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-rnl.out'), 'r', encoding='utf-8') as f:
self.osx_14_6_netstat_rnl = f.read()
#
# output
#
# netstat
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_netstat_json = json.loads(f.read())
@ -102,6 +128,25 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-Abn.json'), 'r', encoding='utf-8') as f:
self.osx_14_6_netstat_Abn_json = json.loads(f.read())
# netsat -r
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-r.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_netstat_r_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-rne.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_netstat_rne_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-rnee.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_netstat_rnee_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-r.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_netstat_r_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-rne.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_netstat_rne_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-rnee.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_netstat_rnee_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-r.json'), 'r', encoding='utf-8') as f:
self.osx_14_6_netstat_r_json = json.loads(f.read())
@ -192,6 +237,42 @@ class MyTests(unittest.TestCase):
"""
self.assertEqual(jc.parsers.netstat.parse(self.osx_14_6_netstat_Abn, quiet=True), self.osx_14_6_netstat_Abn_json)
def test_netstat_r_centos_7_7(self):
"""
Test 'netstat -r' on Centos 7.7
"""
self.assertEqual(jc.parsers.netstat.parse(self.centos_7_7_netstat_r, quiet=True), self.centos_7_7_netstat_r_json)
def test_netstat_rne_centos_7_7(self):
"""
Test 'netstat -rne' on Centos 7.7
"""
self.assertEqual(jc.parsers.netstat.parse(self.centos_7_7_netstat_rne, quiet=True), self.centos_7_7_netstat_rne_json)
def test_netstat_rnee_centos_7_7(self):
"""
Test 'netstat -rnee' on Centos 7.7
"""
self.assertEqual(jc.parsers.netstat.parse(self.centos_7_7_netstat_rnee, quiet=True), self.centos_7_7_netstat_rnee_json)
def test_netstat_r_ubuntu_18_4(self):
"""
Test 'netstat -r' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_r, quiet=True), self.ubuntu_18_4_netstat_r_json)
def test_netstat_rne_ubuntu_18_4(self):
"""
Test 'netstat -rne' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_rne, quiet=True), self.ubuntu_18_4_netstat_rne_json)
def test_netstat_rnee_ubuntu_18_4(self):
"""
Test 'netstat -rnee' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_rnee, quiet=True), self.ubuntu_18_4_netstat_rnee_json)
def test_netstat_r_osx_16_4(self):
"""
Test 'netstat -r' on OSX 16.4