1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/tests/test_resolve_conf.py
Kelly Brazil 4cd721be85 Dev v1.23.4 (#439)
* version bump

* fix regex for crlf line endings

* Completed Ip_route parser (#429)

* tests

* Merge pull request #398 from kellyjonbrazil/dev

Dev v1.23.2

* Merge pull request #398 from kellyjonbrazil/dev

Dev v1.23.2

---------

Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
Co-authored-by: Jjack3032 <julian.jackson@parsons.us>

* formatting

* doc update

* use splitlines

* formatting

* formatting

* Parser for `find` linux command (#434)

* Added find parser and tests for Centos 7.7 and Ubuntu 18.04

* Added a test file, changed logic, and included a case for permission denied returned by find.

* Added a few more lines to the tests

* Changed logic for setting values to null and updated test cases.

* doc update

* doc update

* Added proc_net_tcp parser (#421)

Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>

* clean up net_tcp parser

* add resolve.conf test files

* doc update

* add resolve.conf parser

* doc update

* add sortlist functionality

* add resolve.conf parser tests

* doc update

---------

Co-authored-by: Julian5555 <58196809+Julian5555@users.noreply.github.com>
Co-authored-by: Jjack3032 <julian.jackson@parsons.us>
Co-authored-by: solomonleang <124934439+solomonleang@users.noreply.github.com>
Co-authored-by: AlvinSolomon <41175627+AlvinSolomon@users.noreply.github.com>
2023-07-30 10:08:39 -07:00

84 lines
2.3 KiB
Python

import os
import unittest
import json
from typing import Dict
from jc.parsers.resolve_conf import parse
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
f_in: Dict = {}
f_json: Dict = {}
@classmethod
def setUpClass(cls):
fixtures = {
'resolve_conf_1': (
'fixtures/generic/resolve.conf-1',
'fixtures/generic/resolve.conf-1.json'),
'resolve_conf_2': (
'fixtures/generic/resolve.conf-2',
'fixtures/generic/resolve.conf-2.json'),
'resolve_conf_3': (
'fixtures/generic/resolve.conf-3',
'fixtures/generic/resolve.conf-3.json'),
'resolve_conf_4': (
'fixtures/generic/resolve.conf-4',
'fixtures/generic/resolve.conf-4.json')
}
for file, filepaths in fixtures.items():
with open(os.path.join(THIS_DIR, filepaths[0]), 'r', encoding='utf-8') as a, \
open(os.path.join(THIS_DIR, filepaths[1]), 'r', encoding='utf-8') as b:
cls.f_in[file] = a.read()
cls.f_json[file] = json.loads(b.read())
def test_resolve_conf_nodata(self):
"""
Test 'resolve_conf' with no data
"""
self.assertEqual(parse('', quiet=True), {})
def test_resolve_conf_1(self):
"""
Test 'resolve_conf' file 1
"""
self.assertEqual(
parse(self.f_in['resolve_conf_1'], quiet=True),
self.f_json['resolve_conf_1']
)
def test_resolve_conf_2(self):
"""
Test 'resolve_conf' file 2
"""
self.assertEqual(
parse(self.f_in['resolve_conf_2'], quiet=True),
self.f_json['resolve_conf_2']
)
def test_resolve_conf_3(self):
"""
Test 'resolve_conf' file 3
"""
self.assertEqual(
parse(self.f_in['resolve_conf_3'], quiet=True),
self.f_json['resolve_conf_3']
)
def test_resolve_conf_4(self):
"""
Test 'resolve_conf' file 4
"""
self.assertEqual(
parse(self.f_in['resolve_conf_4'], quiet=True),
self.f_json['resolve_conf_4']
)
if __name__ == '__main__':
unittest.main()