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

77 lines
3.0 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):
def setUp(self):
2019-11-08 17:08:41 -08:00
# input
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()
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()
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()
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
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())
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())
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())
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())
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()