1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-08-08 22:36:48 +02:00

add tests

This commit is contained in:
Kelly Brazil
2022-11-07 16:41:13 -08:00
parent 8a850be857
commit 8d03055b34
5 changed files with 109 additions and 0 deletions

View File

@ -3,6 +3,8 @@ jc changelog
20221107 v1.22.2
- add `sshd_conf` parser for `sshd` configuration files and `sshd -T` output
- add `findmnt` command parser
- add `git ls-remote` command parser
- add `os-prober` command parser
- add SemVer string parser
- enhance the `ifconfig` parser so it can output multiple IPv4 and IPv6 addresses
- enhance the `ifconfig` parser so it can output additional fields common on BSD

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,58 @@
import os
import unittest
import json
from typing import Dict
from jc.parsers.git_ls_remote 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 = {
'git_ls_remote': (
'fixtures/generic/git-ls-remote.out',
'fixtures/generic/git-ls-remote.json'),
'git_ls_remote_raw': (
'fixtures/generic/git-ls-remote.out',
'fixtures/generic/git-ls-remote-raw.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_git_ls_remote_nodata(self):
"""
Test 'git_ls_remote' with no data
"""
self.assertEqual(parse('', quiet=True), {})
def test_git_ls_remote(self):
"""
Test 'git_ls_remote'
"""
self.assertEqual(parse(
self.f_in['git_ls_remote'], quiet=True),
self.f_json['git_ls_remote']
)
def test_git_ls_remote_raw(self):
"""
Test 'git_ls_remote' with raw option
"""
self.assertEqual(parse(
self.f_in['git_ls_remote_raw'], quiet=True, raw=True),
self.f_json['git_ls_remote_raw']
)
if __name__ == '__main__':
unittest.main()

47
tests/test_os_prober.py Normal file
View File

@ -0,0 +1,47 @@
import os
import unittest
import json
from typing import Dict
from jc.parsers.os_prober import parse
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
def test_os_prober_nodata(self):
"""
Test 'os_prober' with no data
"""
self.assertEqual(parse('', quiet=True), {})
def test_os_prober_1(self):
"""
Test 'os_prober' 1
"""
self.assertEqual(parse(
'/dev/sda1:Windows 7 (loader):Windows:chain', quiet=True),
{"partition":"/dev/sda1","name":"Windows 7 (loader)","short_name":"Windows","type":"chain"}
)
def test_os_prober_2(self):
"""
Test 'os_prober' 2
"""
self.assertEqual(parse(
'/dev/sda1:Windows 10:Windows:chain', quiet=True),
{"partition":"/dev/sda1","name":"Windows 10","short_name":"Windows","type":"chain"}
)
def test_os_prober_3(self):
"""
Test 'os_prober' 3
"""
self.assertEqual(parse(
'/dev/sda1@/efi/Microsoft/Boot/bootmgfw.efi:Windows Boot Manager:Windows:efi', quiet=True),
{"partition":"/dev/sda1@/efi/Microsoft/Boot/bootmgfw.efi","name":"Windows Boot Manager","short_name":"Windows","type":"efi"}
)
if __name__ == '__main__':
unittest.main()