diff --git a/tests/fixtures/centos-7.7/fstab.json b/tests/fixtures/centos-7.7/fstab.json new file mode 100644 index 00000000..3fdcde7a --- /dev/null +++ b/tests/fixtures/centos-7.7/fstab.json @@ -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}] diff --git a/tests/fixtures/centos-7.7/fstab.out b/tests/fixtures/centos-7.7/fstab.out new file mode 100644 index 00000000..e5b49f8f --- /dev/null +++ b/tests/fixtures/centos-7.7/fstab.out @@ -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 diff --git a/tests/fixtures/ubuntu-18.04/fstab.json b/tests/fixtures/ubuntu-18.04/fstab.json new file mode 100644 index 00000000..44581b96 --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/fstab.json @@ -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}] diff --git a/tests/fixtures/ubuntu-18.04/fstab.out b/tests/fixtures/ubuntu-18.04/fstab.out new file mode 100644 index 00000000..07dd9495 --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/fstab.out @@ -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 diff --git a/tests/test_fstab.py b/tests/test_fstab.py new file mode 100644 index 00000000..8eb3a034 --- /dev/null +++ b/tests/test_fstab.py @@ -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()