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

add test for last -F output

This commit is contained in:
Kelly Brazil
2021-01-05 13:00:38 -08:00
parent 7ac621e4c9
commit e2c77cb935
3 changed files with 15 additions and 1 deletions

View File

@ -204,6 +204,7 @@ def parse(data, raw=False, quiet=False):
if len(linedata) > 14:
output_line['duration'] = linedata[14].replace('(', '').replace(')', '')
# normal last support
else:
output_line['login'] = ' '.join(linedata[3:7])

View File

@ -0,0 +1 @@
[{"user": "kbrazil", "tty": "pts/0", "hostname": "192.168.71.1", "login": "Tue Jan 5 20:03:51 2021", "logout": "still logged in"}, {"user": "kbrazil", "tty": "pts/0", "hostname": "192.168.71.1", "login": "Tue Jan 5 00:17:29 2021", "logout": "Tue Jan 5 20:03:47 2021", "duration": "19:46"}, {"user": "kbrazil", "tty": "tty1", "hostname": null, "login": "Tue Jan 5 00:08:46 2021", "logout": "gone - no logout"}, {"user": "reboot", "tty": "system boot", "hostname": "5.8.0-34-generic", "login": "Tue Jan 5 00:08:28 2021", "logout": "running"}]

View File

@ -37,6 +37,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/last.out'), 'r', encoding='utf-8') as f:
self.freebsd12_last = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/last-F.out'), 'r', encoding='utf-8') as f:
self.ubuntu_20_4_last_F = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/last.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_last_json = json.loads(f.read())
@ -65,6 +68,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/last.json'), 'r', encoding='utf-8') as f:
self.freebsd12_last_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/last-F.json'), 'r', encoding='utf-8') as f:
self.ubuntu_20_4_last_F_json = json.loads(f.read())
def test_last_nodata(self):
"""
Test plain 'last' with no data
@ -113,6 +119,12 @@ class MyTests(unittest.TestCase):
"""
self.assertEqual(jc.parsers.last.parse(self.ubuntu_18_4_last_w, quiet=True), self.ubuntu_18_4_last_w_json)
def test_last_F_ubuntu_20_4(self):
"""
Test 'last -F' on Ubuntu 20.4
"""
self.assertEqual(jc.parsers.last.parse(self.ubuntu_20_4_last_F, quiet=True), self.ubuntu_20_4_last_F_json)
def test_last_fedora32(self):
"""
Test plain 'last' on Fedora32