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):
|
|
|
|
|
|
|
|
def setUp(self):
|
2019-11-08 17:08:41 -08:00
|
|
|
# input
|
2020-03-04 19:47:03 -08:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/route.out'), 'r', encoding='utf-8') as f:
|
2019-10-29 08:45:11 -07:00
|
|
|
self.centos_7_7_route = f.read()
|
|
|
|
|
2020-03-04 19:47:03 -08:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/route.out'), 'r', encoding='utf-8') as f:
|
2019-10-29 08:45:11 -07:00
|
|
|
self.ubuntu_18_4_route = f.read()
|
|
|
|
|
2020-03-04 19:47:03 -08:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/route-vn.out'), 'r', encoding='utf-8') as f:
|
2019-10-29 08:45:11 -07:00
|
|
|
self.centos_7_7_route_vn = f.read()
|
|
|
|
|
2020-03-04 19:47:03 -08:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/route-vn.out'), 'r', encoding='utf-8') as f:
|
2019-10-29 08:45:11 -07:00
|
|
|
self.ubuntu_18_4_route_vn = f.read()
|
|
|
|
|
2020-05-30 20:33:50 -07:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/nixos/route-ee.out'), 'r', encoding='utf-8') as f:
|
|
|
|
self.nixos_route_ee = f.read()
|
|
|
|
|
2019-11-08 17:08:41 -08:00
|
|
|
# output
|
2020-03-04 19:47:03 -08:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/route.json'), 'r', encoding='utf-8') as f:
|
2019-11-08 17:08:41 -08:00
|
|
|
self.centos_7_7_route_json = json.loads(f.read())
|
|
|
|
|
2020-03-04 19:47:03 -08:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/route.json'), 'r', encoding='utf-8') as f:
|
2019-11-08 17:08:41 -08:00
|
|
|
self.ubuntu_18_4_route_json = json.loads(f.read())
|
|
|
|
|
2020-03-04 19:47:03 -08:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/route-vn.json'), 'r', encoding='utf-8') as f:
|
2019-11-08 17:08:41 -08:00
|
|
|
self.centos_7_7_route_vn_json = json.loads(f.read())
|
|
|
|
|
2020-03-04 19:47:03 -08:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/route-vn.json'), 'r', encoding='utf-8') as f:
|
2019-11-08 17:08:41 -08:00
|
|
|
self.ubuntu_18_4_route_vn_json = json.loads(f.read())
|
|
|
|
|
2020-05-30 20:33:50 -07:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/nixos/route-ee.json'), 'r', encoding='utf-8') as f:
|
|
|
|
self.nixos_route_ee_json = json.loads(f.read())
|
|
|
|
|
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)
|
|
|
|
|
2019-10-29 08:45:11 -07:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|