1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/tests/test_route.py

107 lines
4.1 KiB
Python
Raw Normal View History

2019-10-29 08:45:11 -07:00
import os
2019-11-08 17:08:41 -08:00
import json
2019-10-29 08:45:11 -07:00
import unittest
import jc.parsers.route
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
2022-09-23 14:02:27 -07:00
# input
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/route.out'), 'r', encoding='utf-8') as f:
centos_7_7_route = f.read()
2019-10-29 08:45:11 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/route.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_route = f.read()
2019-10-29 08:45:11 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/route-vn.out'), 'r', encoding='utf-8') as f:
centos_7_7_route_vn = f.read()
2019-10-29 08:45:11 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/route-vn.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_route_vn = f.read()
2019-10-29 08:45:11 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/nixos/route-ee.out'), 'r', encoding='utf-8') as f:
nixos_route_ee = f.read()
2020-05-30 20:33:50 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/route-6.out'), 'r', encoding='utf-8') as f:
centos_7_7_route_6 = f.read()
2020-07-27 20:37:33 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/route-6-n.out'), 'r', encoding='utf-8') as f:
centos_7_7_route_6_n = f.read()
2020-07-27 20:37:33 -07:00
2022-09-23 14:02:27 -07:00
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/route.json'), 'r', encoding='utf-8') as f:
centos_7_7_route_json = json.loads(f.read())
2019-11-08 17:08:41 -08:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/route.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_route_json = json.loads(f.read())
2019-11-08 17:08:41 -08:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/route-vn.json'), 'r', encoding='utf-8') as f:
centos_7_7_route_vn_json = json.loads(f.read())
2019-11-08 17:08:41 -08:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/route-vn.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_route_vn_json = json.loads(f.read())
2019-11-08 17:08:41 -08:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/nixos/route-ee.json'), 'r', encoding='utf-8') as f:
nixos_route_ee_json = json.loads(f.read())
2020-05-30 20:33:50 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/route-6.json'), 'r', encoding='utf-8') as f:
centos_7_7_route_6_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/route-6-n.json'), 'r', encoding='utf-8') as f:
centos_7_7_route_6_n_json = json.loads(f.read())
2020-07-27 20:37:33 -07:00
2020-06-11 17:52:03 -07:00
def test_route_nodata(self):
"""
Test 'route' with no data
"""
self.assertEqual(jc.parsers.route.parse('', quiet=True), [])
2019-10-29 08:45:11 -07:00
def test_route_centos_7_7(self):
"""
Test 'route' on Centos 7.7
"""
2019-11-08 17:08:41 -08:00
self.assertEqual(jc.parsers.route.parse(self.centos_7_7_route, quiet=True), self.centos_7_7_route_json)
2019-10-29 08:45:11 -07:00
def test_route_ubuntu_18_4(self):
"""
Test 'route' on Ubuntu 18.4
"""
2019-11-08 17:08:41 -08:00
self.assertEqual(jc.parsers.route.parse(self.ubuntu_18_4_route, quiet=True), self.ubuntu_18_4_route_json)
2019-10-29 08:45:11 -07:00
def test_route_vn_centos_7_7(self):
"""
Test 'route -vn' on Centos 7.7
"""
2019-11-08 17:08:41 -08:00
self.assertEqual(jc.parsers.route.parse(self.centos_7_7_route_vn, quiet=True), self.centos_7_7_route_vn_json)
2019-10-29 08:45:11 -07:00
def test_route_vn_ubuntu_18_4(self):
"""
Test 'route -vn' on Ubuntu 18.4
"""
2019-11-08 17:08:41 -08:00
self.assertEqual(jc.parsers.route.parse(self.ubuntu_18_4_route_vn, quiet=True), self.ubuntu_18_4_route_vn_json)
2019-10-29 08:45:11 -07:00
2020-05-30 20:33:50 -07:00
def test_route_ee_nixos(self):
"""
Test 'route -ee' on NixOS
"""
self.assertEqual(jc.parsers.route.parse(self.nixos_route_ee, quiet=True), self.nixos_route_ee_json)
2020-07-27 20:37:33 -07:00
def test_route_6_centos_7_7(self):
"""
Test 'route -6' on Centos 7.7
"""
self.assertEqual(jc.parsers.route.parse(self.centos_7_7_route_6, quiet=True), self.centos_7_7_route_6_json)
def test_route_6_n_centos_7_7(self):
"""
Test 'route -6 -n' on Centos 7.7
"""
self.assertEqual(jc.parsers.route.parse(self.centos_7_7_route_6_n, quiet=True), self.centos_7_7_route_6_n_json)
2019-10-29 08:45:11 -07:00
if __name__ == '__main__':
unittest.main()