1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00

add file command tests for #41

This commit is contained in:
Kelly Brazil
2020-03-11 12:39:59 -07:00
parent dfc9618115
commit 59f19d33a5
7 changed files with 153 additions and 0 deletions

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

@ -0,0 +1 @@
[{"filename": "bin", "type": "directory"}, {"filename": "digout", "type": "ASCII text"}, {"filename": "file with spaces in the name", "type": "empty"}, {"filename": "git", "type": "directory"}, {"filename": "id-centos.out", "type": "ASCII text"}, {"filename": "ifcfg.json", "type": "ASCII text, with very long lines"}, {"filename": "ifconfig.out", "type": "ASCII text"}, {"filename": "iptables-tests", "type": "directory"}, {"filename": "journaljson", "type": "ASCII text, with very long lines"}, {"filename": "jp", "type": "ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped"}, {"filename": "jp_1.1.12_linux_x86_64.zip", "type": "Zip archive data, at least v2.0 to extract"}, {"filename": "lastb.out", "type": "ASCII text"}, {"filename": "lsblk-cols", "type": "UTF-8 Unicode text"}, {"filename": "psfile.txt", "type": "ASCII text, with very long lines"}, {"filename": "resizeterm.sh", "type": "Bourne-Again shell script, ASCII text executable"}, {"filename": "routeout", "type": "ASCII text"}, {"filename": "ss-aeep.out", "type": "ASCII text"}, {"filename": "ssout", "type": "ASCII text"}, {"filename": "systemctl.out", "type": "UTF-8 Unicode text"}, {"filename": "testfiles", "type": "directory"}, {"filename": "tmp", "type": "directory"}, {"filename": "top.out", "type": "ASCII text, with escape sequences"}, {"filename": "who-aH.out", "type": "ASCII text"}, {"filename": "who.out", "type": "ASCII text"}, {"filename": "whotext", "type": "ASCII text"}]

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

@ -0,0 +1,25 @@
bin: directory
digout: ASCII text
file with spaces in the name: empty
git: directory
id-centos.out: ASCII text
ifcfg.json: ASCII text, with very long lines
ifconfig.out: ASCII text
iptables-tests: directory
journaljson: ASCII text, with very long lines
jp: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
jp_1.1.12_linux_x86_64.zip: Zip archive data, at least v2.0 to extract
lastb.out: ASCII text
lsblk-cols: UTF-8 Unicode text
psfile.txt: ASCII text, with very long lines
resizeterm.sh: Bourne-Again shell script, ASCII text executable
routeout: ASCII text
ss-aeep.out: ASCII text
ssout: ASCII text
systemctl.out: UTF-8 Unicode text
testfiles: directory
tmp: directory
top.out: ASCII text, with escape sequences
who-aH.out: ASCII text
who.out: ASCII text
whotext: ASCII text

1
tests/fixtures/osx-10.14.6/file.json vendored Normal file
View File

@ -0,0 +1 @@
[{"filename": "Applications", "type": "directory"}, {"filename": "Desktop", "type": "directory"}, {"filename": "Documents", "type": "directory"}, {"filename": "Downloads", "type": "directory"}, {"filename": "Library", "type": "directory"}, {"filename": "Movies", "type": "directory"}, {"filename": "Music", "type": "directory"}, {"filename": "Pictures", "type": "directory"}, {"filename": "Postman", "type": "directory"}, {"filename": "Public", "type": "directory"}, {"filename": "Virtual Machines.localized", "type": "directory"}, {"filename": "another file with spaces", "type": "empty"}, {"filename": "ansible", "type": "directory"}, {"filename": "api", "type": "directory"}, {"filename": "argstest.py", "type": "Python script text executable, ASCII text"}, {"filename": "blkid-p.out", "type": "ASCII text"}, {"filename": "blkid-pi.out", "type": "ASCII text, with very long lines"}, {"filename": "blkid-ubuntu.out", "type": "ASCII text"}, {"filename": "blkid-udev-mult.out", "type": "ASCII text"}, {"filename": "blkid-udev.out", "type": "ASCII text"}, {"filename": "blkid.out", "type": "ASCII text"}, {"filename": "cd_catalog.xml", "type": "XML 1.0 document text, ASCII text, with CRLF line terminators"}, {"filename": "centosserial.sh", "type": "Bourne-Again shell script text executable, UTF-8 Unicode text"}, {"filename": "coreosserial.sh", "type": "Bourne-Again shell script text executable, UTF-8 Unicode text"}, {"filename": "fazserial.sh", "type": "Bourne-Again shell script text executable, UTF-8 Unicode text"}, {"filename": "fgt1serial.sh", "type": "Bourne-Again shell script text executable, UTF-8 Unicode text"}, {"filename": "fgt2serial.sh", "type": "Bourne-Again shell script text executable, UTF-8 Unicode text"}, {"filename": "file with spaces", "type": "empty"}, {"filename": "fortiweb-docker.sh", "type": "Bourne-Again shell script text executable, ASCII text"}, {"filename": "ftmgr.sh", "type": "Bourne-Again shell script text executable, ASCII text"}, {"filename": "git", "type": "directory"}, {"filename": "google-cloud-sdk", "type": "directory"}, {"filename": "ifconfiglines.json", "type": "ASCII text, with very long lines"}, {"filename": "jc-jq-jp-ps-cpu.gif", "type": "GIF image data, version 89a, 1572 x 1212"}, {"filename": "jc-jq-jp-uptime-small.gif", "type": "GIF image data, version 89a, 800 x 617"}, {"filename": "jc-jq-jp-uptime.gif", "type": "GIF image data, version 89a, 1572 x 1212"}, {"filename": "jp", "type": "Mach-O 64-bit executable x86_64"}, {"filename": "jp_1.1.12_osx_x86_64.zip", "type": "Zip archive data, at least v2.0 to extract"}, {"filename": "jupyter.sh", "type": "ASCII text"}, {"filename": "kb.sh", "type": "Bourne-Again shell script text executable, ASCII text"}, {"filename": "kbtesting.txt", "type": "ASCII text"}, {"filename": "kelly-aws.pem", "type": "PEM RSA private key"}, {"filename": "kellyargtest.py", "type": "Python script text executable, ASCII text"}, {"filename": "loadplot.sh", "type": "Bourne-Again shell script text executable, ASCII text"}, {"filename": "ls-R.out", "type": "UTF-8 Unicode text"}, {"filename": "ls-lR-empty-folder.out", "type": "ASCII text"}, {"filename": "ls-lR.out", "type": "UTF-8 Unicode text"}, {"filename": "myrecording", "type": "data"}, {"filename": "smcclient.jnlp", "type": "XML 1.0 document text, ASCII text"}, {"filename": "table.py", "type": "Python script text executable, ASCII text"}, {"filename": "test.ini", "type": "ASCII text"}, {"filename": "ubuntuserial.sh", "type": "Bourne-Again shell script text executable, UTF-8 Unicode text"}, {"filename": "utils", "type": "directory"}]

53
tests/fixtures/osx-10.14.6/file.out vendored Normal file
View File

@ -0,0 +1,53 @@
Applications: directory
Desktop: directory
Documents: directory
Downloads: directory
Library: directory
Movies: directory
Music: directory
Pictures: directory
Postman: directory
Public: directory
Virtual Machines.localized: directory
another file with spaces: empty
ansible: directory
api: directory
argstest.py: Python script text executable, ASCII text
blkid-p.out: ASCII text
blkid-pi.out: ASCII text, with very long lines
blkid-ubuntu.out: ASCII text
blkid-udev-mult.out: ASCII text
blkid-udev.out: ASCII text
blkid.out: ASCII text
cd_catalog.xml: XML 1.0 document text, ASCII text, with CRLF line terminators
centosserial.sh: Bourne-Again shell script text executable, UTF-8 Unicode text
coreosserial.sh: Bourne-Again shell script text executable, UTF-8 Unicode text
fazserial.sh: Bourne-Again shell script text executable, UTF-8 Unicode text
fgt1serial.sh: Bourne-Again shell script text executable, UTF-8 Unicode text
fgt2serial.sh: Bourne-Again shell script text executable, UTF-8 Unicode text
file with spaces: empty
fortiweb-docker.sh: Bourne-Again shell script text executable, ASCII text
ftmgr.sh: Bourne-Again shell script text executable, ASCII text
git: directory
google-cloud-sdk: directory
ifconfiglines.json: ASCII text, with very long lines
jc-jq-jp-ps-cpu.gif: GIF image data, version 89a, 1572 x 1212
jc-jq-jp-uptime-small.gif: GIF image data, version 89a, 800 x 617
jc-jq-jp-uptime.gif: GIF image data, version 89a, 1572 x 1212
jp: Mach-O 64-bit executable x86_64
jp_1.1.12_osx_x86_64.zip: Zip archive data, at least v2.0 to extract
jupyter.sh: ASCII text
kb.sh: Bourne-Again shell script text executable, ASCII text
kbtesting.txt: ASCII text
kelly-aws.pem: PEM RSA private key
kellyargtest.py: Python script text executable, ASCII text
loadplot.sh: Bourne-Again shell script text executable, ASCII text
ls-R.out: UTF-8 Unicode text
ls-lR-empty-folder.out: ASCII text
ls-lR.out: UTF-8 Unicode text
myrecording: data
smcclient.jnlp: XML 1.0 document text, ASCII text
table.py: Python script text executable, ASCII text
test.ini: ASCII text
ubuntuserial.sh: Bourne-Again shell script text executable, UTF-8 Unicode text
utils: directory

1
tests/fixtures/ubuntu-18.04/file.json vendored Normal file
View File

@ -0,0 +1 @@
[{"filename": "crayaml.yaml", "type": "ASCII text"}, {"filename": "git", "type": "directory"}, {"filename": "ifconfig-ubuntu.out", "type": "ASCII text"}, {"filename": "iptables-tests", "type": "directory"}, {"filename": "lastb.out", "type": "ASCII text"}, {"filename": "listjobs", "type": "ASCII text"}, {"filename": "ls-lR.out", "type": "ASCII text"}, {"filename": "ls-R.out", "type": "ASCII text"}, {"filename": "netstat-ae.out", "type": "ASCII text"}, {"filename": "netstat-aew.out", "type": "ASCII text"}, {"filename": "netstat-a.out", "type": "ASCII text"}, {"filename": "netstat-aw.out", "type": "ASCII text"}, {"filename": "resizeterm.sh", "type": "Bourne-Again shell script, ASCII text executable"}, {"filename": "snap", "type": "directory"}, {"filename": "ssout", "type": "ASCII text"}, {"filename": "sudofix", "type": "ASCII text"}, {"filename": "testfiles", "type": "directory"}, {"filename": "tmp", "type": "directory"}, {"filename": "trafficgen.sh", "type": "Bourne-Again shell script, ASCII text executable"}, {"filename": "xmltest.xml", "type": "XML 1.0 document, ASCII text"}]

20
tests/fixtures/ubuntu-18.04/file.out vendored Normal file
View File

@ -0,0 +1,20 @@
crayaml.yaml: ASCII text
git: directory
ifconfig-ubuntu.out: ASCII text
iptables-tests: directory
lastb.out: ASCII text
listjobs: ASCII text
ls-lR.out: ASCII text
ls-R.out: ASCII text
netstat-ae.out: ASCII text
netstat-aew.out: ASCII text
netstat-a.out: ASCII text
netstat-aw.out: ASCII text
resizeterm.sh: Bourne-Again shell script, ASCII text executable
snap: directory
ssout: ASCII text
sudofix: ASCII text
testfiles: directory
tmp: directory
trafficgen.sh: Bourne-Again shell script, ASCII text executable
xmltest.xml: XML 1.0 document, ASCII text

52
tests/test_file.py Normal file
View File

@ -0,0 +1,52 @@
import os
import unittest
import json
import jc.parsers.file
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/file.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_file = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/file.out'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_file = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/file.out'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_file = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/file.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_file_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/file.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_file_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/file.json'), 'r', encoding='utf-8') as f:
self.osx_10_14_6_file_json = json.loads(f.read())
def test_file_centos_7_7(self):
"""
Test 'file *' on Centos 7.7
"""
self.assertEqual(jc.parsers.file.parse(self.centos_7_7_file, quiet=True), self.centos_7_7_file_json)
def test_file_ubuntu_18_4(self):
"""
Test 'file *' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.file.parse(self.ubuntu_18_4_file, quiet=True), self.ubuntu_18_4_file_json)
def test_file_osx_10_14_6(self):
"""
Test 'file *' on OSX 10.14.6
"""
self.assertEqual(jc.parsers.file.parse(self.osx_10_14_6_file, quiet=True), self.osx_10_14_6_file_json)
if __name__ == '__main__':
unittest.main()