1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-13 01:20:24 +02:00

add hash tests

This commit is contained in:
Kelly Brazil
2020-12-30 13:11:13 -08:00
parent 55f360e267
commit d4ae5543f2
3 changed files with 39 additions and 0 deletions

1
tests/fixtures/centos-7.7/hash.json vendored Normal file
View File

@ -0,0 +1 @@
[{"hits": 3, "command": "/usr/bin/sum"}, {"hits": 2, "command": "/usr/bin/cat"}, {"hits": 2, "command": "/usr/bin/cksum"}]

4
tests/fixtures/centos-7.7/hash.out vendored Normal file
View File

@ -0,0 +1,4 @@
hits command
3 /usr/bin/sum
2 /usr/bin/cat
2 /usr/bin/cksum

34
tests/test_hash.py Normal file
View File

@ -0,0 +1,34 @@
import os
import unittest
import json
import jc.parsers.hash
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/hash.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_hash = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/hash.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_hash_json = json.loads(f.read())
def test_hash_nodata(self):
"""
Test 'hash' parser with no data
"""
self.assertEqual(jc.parsers.hash.parse('', quiet=True), [])
def test_hash_centos_7_7(self):
"""
Test 'hash' on Centos 7.7
"""
self.assertEqual(jc.parsers.hash.parse(self.centos_7_7_hash, quiet=True), self.centos_7_7_hash_json)
if __name__ == '__main__':
unittest.main()