mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-23 00:29:59 +02:00
add hashsum tests
This commit is contained in:
1
tests/fixtures/centos-7.7/md5sum.json
vendored
Normal file
1
tests/fixtures/centos-7.7/md5sum.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
[{"filename": "devtoolset-3-gcc-4.9.2-6.el7.x86_64.rpm", "hash": "65fc958c1add637ec23c4b137aecf3d3"}, {"filename": "digout", "hash": "5b9312ee5aff080927753c63a347707d"}, {"filename": "dmidecode.out", "hash": "716fd11c2ac00db109281f7110b8fb9d"}, {"filename": "file with spaces in the name", "hash": "d41d8cd98f00b204e9800998ecf8427e"}, {"filename": "id-centos.out", "hash": "4295be239a14ad77ef3253103de976d2"}, {"filename": "ifcfg.json", "hash": "01fda0d9ba9a75618b072e64ff512b43"}, {"filename": "ifconfig.out", "hash": "e3bff970404527b132dca58031c7286f"}, {"filename": "jc", "hash": "b8b604dc8213d9a6515f2c04bdccfb3b"}, {"filename": "jc-1.10.5-linux.sha256", "hash": "14236ca18714d2b6282758e9b7b46000"}, {"filename": "jc-1.10.5-linux.tar.gz", "hash": "a13b2843c1e8029a98503bc07613862c"}, {"filename": "jc-1.10.5.rpm", "hash": "d0e05de2651857155f8673dc113272ae"}, {"filename": "jc-1.11.1-linux.sha256", "hash": "53e4b33fa99c53c28972db666de9b7b3"}, {"filename": "jc-1.11.1-linux.tar.gz", "hash": "ea4145789224b142361016412cd613b7"}, {"filename": "jc-1.11.1.sha256", "hash": "c6c5fd21ef572dd6d2629c44ad566425"}, {"filename": "jc-1.11.1.tar.gz", "hash": "d838680555f84aff7f286dd440b2490b"}, {"filename": "jc-1.11.2-linux.sha256", "hash": "e7d5c22044848539c2cbd9f5b562de9a"}, {"filename": "jc-1.11.2-linux.tar.gz", "hash": "e6d842ead8cfc9a58df9dce7814ee657"}, {"filename": "jc-1.11.8-linux.sha256", "hash": "24a5005717ab949fd7608aaa77bfeade"}, {"filename": "jc-1.11.8-linux.tar.gz", "hash": "6a84320c7551c51051a748c873d91194"}, {"filename": "jc-1.13.1-linux.sha256", "hash": "54431e32a1ffa7a90f520a6d8ae966fc"}, {"filename": "jc-1.13.1-linux.tar.gz", "hash": "c7a084d9de6bf1193ea0601a2239fc2b"}, {"filename": "jc-1.13.2-linux.sha256", "hash": "1adf518be9a071131ab105155fee176a"}, {"filename": "jc-1.13.2-linux.tar.gz", "hash": "4d8dd74578bc7817de0834e2349c4466"}, {"filename": "jc-1.13.4-linux.sha256", "hash": "3b63bfaff06d9c825aa0a1e0d062a10e"}, {"filename": "jc-1.13.4-linux.tar.gz", "hash": "a5d7feae690e2c3d6bc4acef4205b308"}, {"filename": "jello-1.2.8-linux.sha256", "hash": "90d4fe29d8860adb46f14c99bd27306f"}, {"filename": "jello-1.2.8-linux.tar.gz", "hash": "ea4eadde3abe740d23feb38225e8fe46"}, {"filename": "jello-1.2.9-linux.sha256", "hash": "c690e9126ed296535046e68bfa02de94"}, {"filename": "jello-1.2.9-linux.tar.gz", "hash": "28d6899def6cb63e69d6bb8f53365ecd"}, {"filename": "journaljson", "hash": "5fed1973e223d1f1e45fccec089cb285"}, {"filename": "jp", "hash": "e49f9acb33479f59b7be1f94e8daa3db"}, {"filename": "jp_1.1.12_linux_x86_64.zip", "hash": "ef49750c3f69ae22b8c456e38e4ea39c"}, {"filename": "jq_twitter.json", "hash": "b86c4c8487e3c0bb656d068886c413b7"}, {"filename": "jtbl-1.1.6-linux.sha256", "hash": "d1427e00cbe4e0d1b5b239993ca474b5"}, {"filename": "jtbl-1.1.6-linux.tar.gz", "hash": "87d36c9c35c5ce23f691634d3faad06e"}, {"filename": "kbls.out", "hash": "b3d0c62d77c4f2861cb1dd7464faaa24"}, {"filename": "lastb.out", "hash": "7907a2a62c9f3e1a558ad24ff93fac2c"}, {"filename": "lsblk-cols", "hash": "d9920641b832e86c52e1ef380f777f63"}, {"filename": "ping-ip-O-D.out", "hash": "9ab7407b788aa94b95fe49dbc131b2cb"}, {"filename": "ping-ip-O.out", "hash": "969a0243a76a3bf407e3a24082af8068"}, {"filename": "psfile.txt", "hash": "e1e61d18b3e96359940a22c10f30ad34"}, {"filename": "resizeterm.sh", "hash": "9aa6b53e55b3134219c061441d5c0b3f"}, {"filename": "route-6-n.out", "hash": "e1e1084c23889b46a055d0f8101c0947"}, {"filename": "route-6.out", "hash": "4e75a36fcbf5b1f74c42849c641eb7d4"}, {"filename": "routeout", "hash": "fbb00b1c066988b8d4ce285309fc2a55"}, {"filename": "shafile.txt", "hash": "a54b97e7ffb498130a5807c492fd06bd"}, {"filename": "ss-aeep.out", "hash": "4aa7a33ccd4d863f2dc34570bc9a4761"}, {"filename": "ssout", "hash": "9e61faf4a86f484745e9361a6c33249b"}, {"filename": "systemctl.out", "hash": "eea802ae7bcbb6b63678b5ec68df6212"}, {"filename": "top.out", "hash": "8fc90c98a0b0455ba359199e98a3951a"}, {"filename": "tracepath6.out", "hash": "cdbfa0898a3c089a24ecdab4b62e0241"}, {"filename": "tracepath-cnn.out", "hash": "c5a2a5d40fcf6617d3ca1fae4766f70c"}, {"filename": "tr.out", "hash": "dedcbcfcf486d1620c7495c7c9700a02"}, {"filename": "who-aH.out", "hash": "6a90a054f9df3abdfe936c03e53b71d4"}, {"filename": "who.out", "hash": "d5c25156c301c14125aaa5d1e8f5adbb"}, {"filename": "whotext", "hash": "cbe28a0722637d2ea2c07378eba2206e"}]
|
1
tests/fixtures/centos-7.7/sha256sum.json
vendored
Normal file
1
tests/fixtures/centos-7.7/sha256sum.json
vendored
Normal file
File diff suppressed because one or more lines are too long
1
tests/fixtures/centos-7.7/sha384sum.json
vendored
Normal file
1
tests/fixtures/centos-7.7/sha384sum.json
vendored
Normal file
File diff suppressed because one or more lines are too long
1
tests/fixtures/osx-10.14.6/md5.json
vendored
Normal file
1
tests/fixtures/osx-10.14.6/md5.json
vendored
Normal file
File diff suppressed because one or more lines are too long
1
tests/fixtures/osx-10.14.6/shasum.json
vendored
Normal file
1
tests/fixtures/osx-10.14.6/shasum.json
vendored
Normal file
File diff suppressed because one or more lines are too long
82
tests/test_hashsum.py
Normal file
82
tests/test_hashsum.py
Normal file
@ -0,0 +1,82 @@
|
||||
import os
|
||||
import unittest
|
||||
import json
|
||||
import jc.parsers.hashsum
|
||||
|
||||
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/md5sum.out'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_md5sum = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sha256sum.out'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_sha256sum = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sha384sum.out'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_sha384sum = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/md5.out'), 'r', encoding='utf-8') as f:
|
||||
self.osx_10_14_6_md5 = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/shasum.out'), 'r', encoding='utf-8') as f:
|
||||
self.osx_10_14_6_shasum = f.read()
|
||||
|
||||
# output
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/md5sum.json'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_md5sum_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sha256sum.json'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_sha256sum_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sha384sum.json'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_sha384sum_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/md5.json'), 'r', encoding='utf-8') as f:
|
||||
self.osx_10_14_6_md5_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/shasum.json'), 'r', encoding='utf-8') as f:
|
||||
self.osx_10_14_6_shasum_json = json.loads(f.read())
|
||||
|
||||
def test_hashsum_nodata(self):
|
||||
"""
|
||||
Test 'hashsum' with no data
|
||||
"""
|
||||
self.assertEqual(jc.parsers.hashsum.parse('', quiet=True), [])
|
||||
|
||||
def test_md5sum_centos_7_7(self):
|
||||
"""
|
||||
Test 'md5sum' on Centos 7.7
|
||||
"""
|
||||
self.assertEqual(jc.parsers.hashsum.parse(self.centos_7_7_md5sum, quiet=True), self.centos_7_7_md5sum_json)
|
||||
|
||||
def test_sha256sum_centos_7_7(self):
|
||||
"""
|
||||
Test 'sha256sum' on Centos 7.7
|
||||
"""
|
||||
self.assertEqual(jc.parsers.hashsum.parse(self.centos_7_7_sha256sum, quiet=True), self.centos_7_7_sha256sum_json)
|
||||
|
||||
def test_sha384sum_centos_7_7(self):
|
||||
"""
|
||||
Test 'sha384sum' on Centos 7.7
|
||||
"""
|
||||
self.assertEqual(jc.parsers.hashsum.parse(self.centos_7_7_sha384sum, quiet=True), self.centos_7_7_sha384sum_json)
|
||||
|
||||
def test_md5_osx_10_14_6(self):
|
||||
"""
|
||||
Test 'md5' on OSX 10.14.6
|
||||
"""
|
||||
self.assertEqual(jc.parsers.hashsum.parse(self.osx_10_14_6_md5, quiet=True), self.osx_10_14_6_md5_json)
|
||||
|
||||
def test_shasum_osx_10_14_6(self):
|
||||
"""
|
||||
Test 'shasum' on OSX 10.14.6
|
||||
"""
|
||||
self.assertEqual(jc.parsers.hashsum.parse(self.osx_10_14_6_shasum, quiet=True), self.osx_10_14_6_shasum_json)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in New Issue
Block a user