diff --git a/tests/fixtures/centos-7.7/hash.json b/tests/fixtures/centos-7.7/hash.json new file mode 100644 index 00000000..3427281c --- /dev/null +++ b/tests/fixtures/centos-7.7/hash.json @@ -0,0 +1 @@ +[{"hits": 3, "command": "/usr/bin/sum"}, {"hits": 2, "command": "/usr/bin/cat"}, {"hits": 2, "command": "/usr/bin/cksum"}] diff --git a/tests/fixtures/centos-7.7/hash.out b/tests/fixtures/centos-7.7/hash.out new file mode 100644 index 00000000..98582263 --- /dev/null +++ b/tests/fixtures/centos-7.7/hash.out @@ -0,0 +1,4 @@ +hits command + 3 /usr/bin/sum + 2 /usr/bin/cat + 2 /usr/bin/cksum diff --git a/tests/test_hash.py b/tests/test_hash.py new file mode 100644 index 00000000..f370fc15 --- /dev/null +++ b/tests/test_hash.py @@ -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()