1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-13 01:20:24 +02:00

add fstab tests

This commit is contained in:
Kelly Brazil
2019-11-17 10:26:48 -08:00
parent 98c0188821
commit a0298ac8a3
5 changed files with 55 additions and 0 deletions

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

@ -0,0 +1 @@
[{"fs_spec": "/dev/mapper/centos-root", "fs_file": "/", "fs_vfstype": "xfs", "fs_mntops": "defaults", "fs_freq": 0, "fs_passno": 0}, {"fs_spec": "UUID=05d927bb-5875-49e3-ada1-7f46cb31c932", "fs_file": "/boot", "fs_vfstype": "xfs", "fs_mntops": "defaults", "fs_freq": 0, "fs_passno": 0}, {"fs_spec": "/dev/mapper/centos-swap", "fs_file": "swap", "fs_vfstype": "swap", "fs_mntops": "defaults", "fs_freq": 0, "fs_passno": 0}]

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

@ -0,0 +1,11 @@
#
# /etc/fstab
# Created by anaconda on Thu Aug 15 10:53:00 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=05d927bb-5875-49e3-ada1-7f46cb31c932 /boot xfs defaults 0 0 # this is a comment
/dev/mapper/centos-swap swap swap defaults 0 0

View File

@ -0,0 +1 @@
[{"fs_spec": "UUID=011527a0-c72a-4c00-a50e-ee90da26b6e2", "fs_file": "/", "fs_vfstype": "ext4", "fs_mntops": "defaults", "fs_freq": 0, "fs_passno": 0}, {"fs_spec": "/swap.img", "fs_file": "none", "fs_vfstype": "swap", "fs_mntops": "sw", "fs_freq": 0, "fs_passno": 0}]

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

@ -0,0 +1,2 @@
UUID=011527a0-c72a-4c00-a50e-ee90da26b6e2 / ext4 defaults 0 0
/swap.img none swap sw 0 0 # this is a comment

40
tests/test_fstab.py Normal file
View File

@ -0,0 +1,40 @@
import os
import json
import unittest
import jc.parsers.fstab
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/fstab.out'), 'r') as f:
self.centos_7_7_fstab = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/fstab.out'), 'r') as f:
self.ubuntu_18_4_fstab = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/fstab.json'), 'r') as f:
self.centos_7_7_fstab_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/fstab.json'), 'r') as f:
self.ubuntu_18_4_fstab_json = json.loads(f.read())
def test_fstab_centos_7_7(self):
"""
Test 'cat /etc/fstab' on Centos 7.7
"""
self.assertEqual(jc.parsers.fstab.parse(self.centos_7_7_fstab, quiet=True), self.centos_7_7_fstab_json)
def test_fstab_ubuntu_18_4(self):
"""
Test 'cat /etc/fstab' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.fstab.parse(self.ubuntu_18_4_fstab, quiet=True), self.ubuntu_18_4_fstab_json)
if __name__ == '__main__':
unittest.main()