From d4ae5543f2d5f28a0db5b8e2e19993c21c5d960c Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Wed, 30 Dec 2020 13:11:13 -0800 Subject: [PATCH] add hash tests --- tests/fixtures/centos-7.7/hash.json | 1 + tests/fixtures/centos-7.7/hash.out | 4 ++++ tests/test_hash.py | 34 +++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 tests/fixtures/centos-7.7/hash.json create mode 100644 tests/fixtures/centos-7.7/hash.out create mode 100644 tests/test_hash.py 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()