mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-08-10 22:41:51 +02:00
add hosts tests
This commit is contained in:
1
tests/fixtures/centos-7.7/hosts.json
vendored
Normal file
1
tests/fixtures/centos-7.7/hosts.json
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[{"ip": "127.0.0.1", "hostname": ["localhost", "localhost.localdomain", "localhost4", "localhost4.localdomain4"]}, {"ip": "::1", "hostname": ["localhost", "localhost.localdomain", "localhost6", "localhost6.localdomain6"]}]
|
2
tests/fixtures/centos-7.7/hosts.out
vendored
Normal file
2
tests/fixtures/centos-7.7/hosts.out
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
|
||||||
|
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
|
1
tests/fixtures/ubuntu-18.04/hosts.json
vendored
Normal file
1
tests/fixtures/ubuntu-18.04/hosts.json
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[{"ip": "127.0.0.1", "hostname": ["localhost"]}, {"ip": "127.0.1.1", "hostname": ["kbrazil-ubuntu"]}, {"ip": "::1", "hostname": ["ip6-localhost", "ip6-loopback"]}, {"ip": "fe00::0", "hostname": ["ip6-localnet"]}, {"ip": "ff00::0", "hostname": ["ip6-mcastprefix"]}, {"ip": "ff02::1", "hostname": ["ip6-allnodes"]}, {"ip": "ff02::2", "hostname": ["ip6-allrouters"]}]
|
9
tests/fixtures/ubuntu-18.04/hosts.out
vendored
Normal file
9
tests/fixtures/ubuntu-18.04/hosts.out
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
127.0.0.1 localhost
|
||||||
|
127.0.1.1 kbrazil-ubuntu
|
||||||
|
|
||||||
|
# The following lines are desirable for IPv6 capable hosts
|
||||||
|
::1 ip6-localhost ip6-loopback
|
||||||
|
fe00::0 ip6-localnet
|
||||||
|
ff00::0 ip6-mcastprefix
|
||||||
|
ff02::1 ip6-allnodes
|
||||||
|
ff02::2 ip6-allrouters
|
40
tests/test_hosts.py
Normal file
40
tests/test_hosts.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import os
|
||||||
|
import json
|
||||||
|
import unittest
|
||||||
|
import jc.parsers.hosts
|
||||||
|
|
||||||
|
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
|
||||||
|
class MyTests(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
# input
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/hosts.out'), 'r') as f:
|
||||||
|
self.centos_7_7_hosts = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/hosts.out'), 'r') as f:
|
||||||
|
self.ubuntu_18_4_hosts = f.read()
|
||||||
|
|
||||||
|
# output
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/hosts.json'), 'r') as f:
|
||||||
|
self.centos_7_7_hosts_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/hosts.json'), 'r') as f:
|
||||||
|
self.ubuntu_18_4_hosts_json = json.loads(f.read())
|
||||||
|
|
||||||
|
def test_hosts_centos_7_7(self):
|
||||||
|
"""
|
||||||
|
Test 'cat /etc/hosts' on Centos 7.7
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.hosts.parse(self.centos_7_7_hosts, quiet=True), self.centos_7_7_hosts_json)
|
||||||
|
|
||||||
|
def test_hosts_ubuntu_18_4(self):
|
||||||
|
"""
|
||||||
|
Test 'cat /etc/hosts' on Ubuntu 18.4
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.hosts.parse(self.ubuntu_18_4_hosts, quiet=True), self.ubuntu_18_4_hosts_json)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Reference in New Issue
Block a user