2019-10-29 08:45:11 -07:00
|
|
|
import os
|
2019-11-08 17:08:41 -08:00
|
|
|
import json
|
2019-10-29 08:45:11 -07:00
|
|
|
import unittest
|
|
|
|
import jc.parsers.ps
|
|
|
|
|
|
|
|
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
|
|
|
|
|
|
class MyTests(unittest.TestCase):
|
|
|
|
|
2022-09-23 14:02:27 -07:00
|
|
|
# input
|
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ps-ef.out'), 'r', encoding='utf-8') as f:
|
|
|
|
centos_7_7_ps_ef = f.read()
|
2019-10-29 08:45:11 -07:00
|
|
|
|
2022-09-23 14:02:27 -07:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ps-ef.out'), 'r', encoding='utf-8') as f:
|
|
|
|
ubuntu_18_4_ps_ef = f.read()
|
2019-10-29 08:45:11 -07:00
|
|
|
|
2022-09-23 14:02:27 -07:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.11.6/ps-ef.out'), 'r', encoding='utf-8') as f:
|
|
|
|
osx_10_11_6_ps_ef = f.read()
|
2019-12-13 14:30:12 -08:00
|
|
|
|
2022-09-23 14:02:27 -07:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ps-ef.out'), 'r', encoding='utf-8') as f:
|
|
|
|
osx_10_14_6_ps_ef = f.read()
|
2019-12-12 15:59:24 -08:00
|
|
|
|
2022-09-23 14:02:27 -07:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ps-axu.out'), 'r', encoding='utf-8') as f:
|
|
|
|
centos_7_7_ps_axu = f.read()
|
2019-10-29 08:45:11 -07:00
|
|
|
|
2022-09-23 14:02:27 -07:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ps-axu.out'), 'r', encoding='utf-8') as f:
|
|
|
|
ubuntu_18_4_ps_axu = f.read()
|
2019-10-29 08:45:11 -07:00
|
|
|
|
2022-09-23 14:02:27 -07:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.11.6/ps-axu.out'), 'r', encoding='utf-8') as f:
|
|
|
|
osx_10_11_6_ps_axu = f.read()
|
2019-12-13 14:30:12 -08:00
|
|
|
|
2022-09-23 14:02:27 -07:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ps-axu.out'), 'r', encoding='utf-8') as f:
|
|
|
|
osx_10_14_6_ps_axu = f.read()
|
2019-12-12 15:59:24 -08:00
|
|
|
|
2022-09-23 14:02:27 -07:00
|
|
|
# output
|
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ps-ef.json'), 'r', encoding='utf-8') as f:
|
|
|
|
centos_7_7_ps_ef_json = json.loads(f.read())
|
2019-11-08 17:08:41 -08:00
|
|
|
|
2022-09-23 14:02:27 -07:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ps-ef.json'), 'r', encoding='utf-8') as f:
|
|
|
|
ubuntu_18_4_ps_ef_json = json.loads(f.read())
|
2019-11-08 17:08:41 -08:00
|
|
|
|
2022-09-23 14:02:27 -07:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.11.6/ps-ef.json'), 'r', encoding='utf-8') as f:
|
|
|
|
osx_10_11_6_ps_ef_json = json.loads(f.read())
|
2019-12-13 14:30:12 -08:00
|
|
|
|
2022-09-23 14:02:27 -07:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ps-ef.json'), 'r', encoding='utf-8') as f:
|
|
|
|
osx_10_14_6_ps_ef_json = json.loads(f.read())
|
2019-12-12 15:59:24 -08:00
|
|
|
|
2022-09-23 14:02:27 -07:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ps-axu.json'), 'r', encoding='utf-8') as f:
|
|
|
|
centos_7_7_ps_axu_json = json.loads(f.read())
|
2019-11-08 17:08:41 -08:00
|
|
|
|
2022-09-23 14:02:27 -07:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ps-axu.json'), 'r', encoding='utf-8') as f:
|
|
|
|
ubuntu_18_4_ps_axu_json = json.loads(f.read())
|
2019-11-08 17:08:41 -08:00
|
|
|
|
2022-09-23 14:02:27 -07:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.11.6/ps-axu.json'), 'r', encoding='utf-8') as f:
|
|
|
|
osx_10_11_6_ps_axu_json = json.loads(f.read())
|
|
|
|
|
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ps-axu.json'), 'r', encoding='utf-8') as f:
|
|
|
|
osx_10_14_6_ps_axu_json = json.loads(f.read())
|
2019-12-13 14:30:12 -08:00
|
|
|
|
2019-12-12 15:59:24 -08:00
|
|
|
|
2020-06-11 17:52:03 -07:00
|
|
|
def test_ps_nodata(self):
|
|
|
|
"""
|
|
|
|
Test 'ps' with no data
|
|
|
|
"""
|
|
|
|
self.assertEqual(jc.parsers.ps.parse('', quiet=True), [])
|
|
|
|
|
2019-10-29 08:45:11 -07:00
|
|
|
def test_ps_ef_centos_7_7(self):
|
|
|
|
"""
|
|
|
|
Test 'ps -ef' on Centos 7.7
|
|
|
|
"""
|
2019-11-08 17:08:41 -08:00
|
|
|
self.assertEqual(jc.parsers.ps.parse(self.centos_7_7_ps_ef, quiet=True), self.centos_7_7_ps_ef_json)
|
2019-10-29 08:45:11 -07:00
|
|
|
|
|
|
|
def test_ps_ef_ubuntu_18_4(self):
|
|
|
|
"""
|
|
|
|
Test 'ps -ef' on Ubuntu 18.4
|
|
|
|
"""
|
2019-11-08 17:08:41 -08:00
|
|
|
self.assertEqual(jc.parsers.ps.parse(self.ubuntu_18_4_ps_ef, quiet=True), self.ubuntu_18_4_ps_ef_json)
|
2019-10-29 08:45:11 -07:00
|
|
|
|
2019-12-13 14:30:12 -08:00
|
|
|
def test_ps_ef_osx_10_11_6(self):
|
|
|
|
"""
|
|
|
|
Test 'ps -ef' on OSX 10.11.6
|
|
|
|
"""
|
|
|
|
self.assertEqual(jc.parsers.ps.parse(self.osx_10_11_6_ps_ef, quiet=True), self.osx_10_11_6_ps_ef_json)
|
|
|
|
|
2019-12-12 15:59:24 -08:00
|
|
|
def test_ps_ef_osx_10_14_6(self):
|
|
|
|
"""
|
|
|
|
Test 'ps -ef' on OSX 10.14.6
|
|
|
|
"""
|
|
|
|
self.assertEqual(jc.parsers.ps.parse(self.osx_10_14_6_ps_ef, quiet=True), self.osx_10_14_6_ps_ef_json)
|
|
|
|
|
2019-10-29 08:45:11 -07:00
|
|
|
def test_ps_axu_centos_7_7(self):
|
|
|
|
"""
|
|
|
|
Test 'ps axu' on Centos 7.7
|
|
|
|
"""
|
2019-11-08 17:08:41 -08:00
|
|
|
self.assertEqual(jc.parsers.ps.parse(self.centos_7_7_ps_axu, quiet=True), self.centos_7_7_ps_axu_json)
|
2019-10-29 08:45:11 -07:00
|
|
|
|
|
|
|
def test_ps_axu_ubuntu_18_4(self):
|
|
|
|
"""
|
|
|
|
Test 'ps axu' on Ubuntu 18.4
|
|
|
|
"""
|
2019-11-08 17:08:41 -08:00
|
|
|
self.assertEqual(jc.parsers.ps.parse(self.ubuntu_18_4_ps_axu, quiet=True), self.ubuntu_18_4_ps_axu_json)
|
2019-10-29 08:45:11 -07:00
|
|
|
|
2019-12-13 14:30:12 -08:00
|
|
|
def test_ps_axu_osx_10_11_6(self):
|
|
|
|
"""
|
|
|
|
Test 'ps axu' on OSX 10.11.6
|
|
|
|
"""
|
|
|
|
self.assertEqual(jc.parsers.ps.parse(self.osx_10_11_6_ps_axu, quiet=True), self.osx_10_11_6_ps_axu_json)
|
|
|
|
|
2019-12-12 15:59:24 -08:00
|
|
|
def test_ps_axu_osx_10_14_6(self):
|
|
|
|
"""
|
|
|
|
Test 'ps axu' on OSX 10.14.6
|
|
|
|
"""
|
|
|
|
self.assertEqual(jc.parsers.ps.parse(self.osx_10_14_6_ps_axu, quiet=True), self.osx_10_14_6_ps_axu_json)
|
|
|
|
|
2019-10-29 08:45:11 -07:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|