From 01f92ced813fa72ad3c8f497cfd55886227a0387 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 1 Nov 2022 13:15:31 -0700 Subject: [PATCH] add docs and tests for findmnt --- README.md | 1 + completions/jc_bash_completion.sh | 4 +- completions/jc_zsh_completion.sh | 6 +- docs/parsers/findmnt.md | 116 +++++++++++++++++++++++++ jc/parsers/findmnt.py | 62 +++++++++++-- man/jc.1 | 7 +- tests/fixtures/centos-7.7/findmnt.json | 1 + tests/test_findmnt.py | 44 ++++++++++ 8 files changed, 230 insertions(+), 11 deletions(-) create mode 100644 docs/parsers/findmnt.md create mode 100644 tests/fixtures/centos-7.7/findmnt.json create mode 100644 tests/test_findmnt.py diff --git a/README.md b/README.md index 2cf9eb05..837e98ea 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,7 @@ option. | `--email-address` | Email Address string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/email_address) | | ` --env` | `env` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/env) | | ` --file` | `file` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/file) | +| ` --findmnt` | `findmnt` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/findmnt) | | ` --finger` | `finger` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/finger) | | ` --free` | `free` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/free) | | ` --fstab` | `/etc/fstab` file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/fstab) | diff --git a/completions/jc_bash_completion.sh b/completions/jc_bash_completion.sh index c39360e2..da908778 100644 --- a/completions/jc_bash_completion.sh +++ b/completions/jc_bash_completion.sh @@ -3,8 +3,8 @@ _jc() local cur prev words cword jc_commands jc_parsers jc_options \ jc_about_options jc_about_mod_options jc_help_options jc_special_options - jc_commands=(acpi airport arp blkid chage cksum crontab date df dig dmidecode dpkg du env file finger free git gpg hciconfig id ifconfig iostat iptables iw jobs last lastb ls lsblk lsmod lsof lspci lsusb md5 md5sum mdadm mount mpstat netstat nmcli ntpq pidstat ping ping6 pip pip3 postconf printenv ps route rpm rsync sfdisk sha1sum sha224sum sha256sum sha384sum sha512sum shasum ss sshd stat sum sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 udevadm ufw uname update-alternatives upower uptime vdir vmstat w wc who xrandr zipinfo) - jc_parsers=(--acpi --airport --airport-s --arp --asciitable --asciitable-m --blkid --cef --cef-s --chage --cksum --crontab --crontab-u --csv --csv-s --date --datetime-iso --df --dig --dir --dmidecode --dpkg-l --du --email-address --env --file --finger --free --fstab --git-log --git-log-s --gpg --group --gshadow --hash --hashsum --hciconfig --history --hosts --id --ifconfig --ini --iostat --iostat-s --ip-address --iptables --iw-scan --jar-manifest --jobs --jwt --kv --last --ls --ls-s --lsblk --lsmod --lsof --lspci --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --netstat --nmcli --ntpq --passwd --pci-ids --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --plist --postconf --proc --proc-buddyinfo --proc-consoles --proc-cpuinfo --proc-crypto --proc-devices --proc-diskstats --proc-filesystems --proc-interrupts --proc-iomem --proc-ioports --proc-loadavg --proc-locks --proc-meminfo --proc-modules --proc-mtrr --proc-pagetypeinfo --proc-partitions --proc-slabinfo --proc-softirqs --proc-stat --proc-swaps --proc-uptime --proc-version --proc-vmallocinfo --proc-vmstat --proc-zoneinfo --proc-driver-rtc --proc-net-arp --proc-net-dev --proc-net-dev-mcast --proc-net-if-inet6 --proc-net-igmp --proc-net-igmp6 --proc-net-ipv6-route --proc-net-netlink --proc-net-netstat --proc-net-packet --proc-net-protocols --proc-net-route --proc-net-unix --proc-pid-fdinfo --proc-pid-io --proc-pid-maps --proc-pid-mountinfo --proc-pid-numa-maps --proc-pid-smaps --proc-pid-stat --proc-pid-statm --proc-pid-status --ps --route --rpm-qi --rsync --rsync-s --sfdisk --shadow --ss --sshd-conf --stat --stat-s --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --top --top-s --tracepath --traceroute --udevadm --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --vmstat --vmstat-s --w --wc --who --x509-cert --xml --xrandr --yaml --zipinfo) + jc_commands=(acpi airport arp blkid chage cksum crontab date df dig dmidecode dpkg du env file findmnt finger free git gpg hciconfig id ifconfig iostat iptables iw jobs last lastb ls lsblk lsmod lsof lspci lsusb md5 md5sum mdadm mount mpstat netstat nmcli ntpq pidstat ping ping6 pip pip3 postconf printenv ps route rpm rsync sfdisk sha1sum sha224sum sha256sum sha384sum sha512sum shasum ss sshd stat sum sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 udevadm ufw uname update-alternatives upower uptime vdir vmstat w wc who xrandr zipinfo) + jc_parsers=(--acpi --airport --airport-s --arp --asciitable --asciitable-m --blkid --cef --cef-s --chage --cksum --crontab --crontab-u --csv --csv-s --date --datetime-iso --df --dig --dir --dmidecode --dpkg-l --du --email-address --env --file --findmnt --finger --free --fstab --git-log --git-log-s --gpg --group --gshadow --hash --hashsum --hciconfig --history --hosts --id --ifconfig --ini --iostat --iostat-s --ip-address --iptables --iw-scan --jar-manifest --jobs --jwt --kv --last --ls --ls-s --lsblk --lsmod --lsof --lspci --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --netstat --nmcli --ntpq --passwd --pci-ids --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --plist --postconf --proc --proc-buddyinfo --proc-consoles --proc-cpuinfo --proc-crypto --proc-devices --proc-diskstats --proc-filesystems --proc-interrupts --proc-iomem --proc-ioports --proc-loadavg --proc-locks --proc-meminfo --proc-modules --proc-mtrr --proc-pagetypeinfo --proc-partitions --proc-slabinfo --proc-softirqs --proc-stat --proc-swaps --proc-uptime --proc-version --proc-vmallocinfo --proc-vmstat --proc-zoneinfo --proc-driver-rtc --proc-net-arp --proc-net-dev --proc-net-dev-mcast --proc-net-if-inet6 --proc-net-igmp --proc-net-igmp6 --proc-net-ipv6-route --proc-net-netlink --proc-net-netstat --proc-net-packet --proc-net-protocols --proc-net-route --proc-net-unix --proc-pid-fdinfo --proc-pid-io --proc-pid-maps --proc-pid-mountinfo --proc-pid-numa-maps --proc-pid-smaps --proc-pid-stat --proc-pid-statm --proc-pid-status --ps --route --rpm-qi --rsync --rsync-s --sfdisk --shadow --ss --sshd-conf --stat --stat-s --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --top --top-s --tracepath --traceroute --udevadm --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --vmstat --vmstat-s --w --wc --who --x509-cert --xml --xrandr --yaml --zipinfo) jc_options=(--force-color -C --debug -d --monochrome -m --meta-out -M --pretty -p --quiet -q --raw -r --unbuffer -u --yaml-out -y) jc_about_options=(--about -a) jc_about_mod_options=(--pretty -p --yaml-out -y --monochrome -m --force-color -C) diff --git a/completions/jc_zsh_completion.sh b/completions/jc_zsh_completion.sh index d2ac8da2..87432670 100644 --- a/completions/jc_zsh_completion.sh +++ b/completions/jc_zsh_completion.sh @@ -9,7 +9,7 @@ _jc() { jc_help_options jc_help_options_describe \ jc_special_options jc_special_options_describe - jc_commands=(acpi airport arp blkid chage cksum crontab date df dig dmidecode dpkg du env file finger free git gpg hciconfig id ifconfig iostat iptables iw jobs last lastb ls lsblk lsmod lsof lspci lsusb md5 md5sum mdadm mount mpstat netstat nmcli ntpq pidstat ping ping6 pip pip3 postconf printenv ps route rpm rsync sfdisk sha1sum sha224sum sha256sum sha384sum sha512sum shasum ss sshd stat sum sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 udevadm ufw uname update-alternatives upower uptime vdir vmstat w wc who xrandr zipinfo) + jc_commands=(acpi airport arp blkid chage cksum crontab date df dig dmidecode dpkg du env file findmnt finger free git gpg hciconfig id ifconfig iostat iptables iw jobs last lastb ls lsblk lsmod lsof lspci lsusb md5 md5sum mdadm mount mpstat netstat nmcli ntpq pidstat ping ping6 pip pip3 postconf printenv ps route rpm rsync sfdisk sha1sum sha224sum sha256sum sha384sum sha512sum shasum ss sshd stat sum sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 udevadm ufw uname update-alternatives upower uptime vdir vmstat w wc who xrandr zipinfo) jc_commands_describe=( 'acpi:run "acpi" command with magic syntax.' 'airport:run "airport" command with magic syntax.' @@ -26,6 +26,7 @@ _jc() { 'du:run "du" command with magic syntax.' 'env:run "env" command with magic syntax.' 'file:run "file" command with magic syntax.' + 'findmnt:run "findmnt" command with magic syntax.' 'finger:run "finger" command with magic syntax.' 'free:run "free" command with magic syntax.' 'git:run "git" command with magic syntax.' @@ -98,7 +99,7 @@ _jc() { 'xrandr:run "xrandr" command with magic syntax.' 'zipinfo:run "zipinfo" command with magic syntax.' ) - jc_parsers=(--acpi --airport --airport-s --arp --asciitable --asciitable-m --blkid --cef --cef-s --chage --cksum --crontab --crontab-u --csv --csv-s --date --datetime-iso --df --dig --dir --dmidecode --dpkg-l --du --email-address --env --file --finger --free --fstab --git-log --git-log-s --gpg --group --gshadow --hash --hashsum --hciconfig --history --hosts --id --ifconfig --ini --iostat --iostat-s --ip-address --iptables --iw-scan --jar-manifest --jobs --jwt --kv --last --ls --ls-s --lsblk --lsmod --lsof --lspci --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --netstat --nmcli --ntpq --passwd --pci-ids --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --plist --postconf --proc --proc-buddyinfo --proc-consoles --proc-cpuinfo --proc-crypto --proc-devices --proc-diskstats --proc-filesystems --proc-interrupts --proc-iomem --proc-ioports --proc-loadavg --proc-locks --proc-meminfo --proc-modules --proc-mtrr --proc-pagetypeinfo --proc-partitions --proc-slabinfo --proc-softirqs --proc-stat --proc-swaps --proc-uptime --proc-version --proc-vmallocinfo --proc-vmstat --proc-zoneinfo --proc-driver-rtc --proc-net-arp --proc-net-dev --proc-net-dev-mcast --proc-net-if-inet6 --proc-net-igmp --proc-net-igmp6 --proc-net-ipv6-route --proc-net-netlink --proc-net-netstat --proc-net-packet --proc-net-protocols --proc-net-route --proc-net-unix --proc-pid-fdinfo --proc-pid-io --proc-pid-maps --proc-pid-mountinfo --proc-pid-numa-maps --proc-pid-smaps --proc-pid-stat --proc-pid-statm --proc-pid-status --ps --route --rpm-qi --rsync --rsync-s --sfdisk --shadow --ss --sshd-conf --stat --stat-s --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --top --top-s --tracepath --traceroute --udevadm --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --vmstat --vmstat-s --w --wc --who --x509-cert --xml --xrandr --yaml --zipinfo) + jc_parsers=(--acpi --airport --airport-s --arp --asciitable --asciitable-m --blkid --cef --cef-s --chage --cksum --crontab --crontab-u --csv --csv-s --date --datetime-iso --df --dig --dir --dmidecode --dpkg-l --du --email-address --env --file --findmnt --finger --free --fstab --git-log --git-log-s --gpg --group --gshadow --hash --hashsum --hciconfig --history --hosts --id --ifconfig --ini --iostat --iostat-s --ip-address --iptables --iw-scan --jar-manifest --jobs --jwt --kv --last --ls --ls-s --lsblk --lsmod --lsof --lspci --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --netstat --nmcli --ntpq --passwd --pci-ids --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --plist --postconf --proc --proc-buddyinfo --proc-consoles --proc-cpuinfo --proc-crypto --proc-devices --proc-diskstats --proc-filesystems --proc-interrupts --proc-iomem --proc-ioports --proc-loadavg --proc-locks --proc-meminfo --proc-modules --proc-mtrr --proc-pagetypeinfo --proc-partitions --proc-slabinfo --proc-softirqs --proc-stat --proc-swaps --proc-uptime --proc-version --proc-vmallocinfo --proc-vmstat --proc-zoneinfo --proc-driver-rtc --proc-net-arp --proc-net-dev --proc-net-dev-mcast --proc-net-if-inet6 --proc-net-igmp --proc-net-igmp6 --proc-net-ipv6-route --proc-net-netlink --proc-net-netstat --proc-net-packet --proc-net-protocols --proc-net-route --proc-net-unix --proc-pid-fdinfo --proc-pid-io --proc-pid-maps --proc-pid-mountinfo --proc-pid-numa-maps --proc-pid-smaps --proc-pid-stat --proc-pid-statm --proc-pid-status --ps --route --rpm-qi --rsync --rsync-s --sfdisk --shadow --ss --sshd-conf --stat --stat-s --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --top --top-s --tracepath --traceroute --udevadm --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --vmstat --vmstat-s --w --wc --who --x509-cert --xml --xrandr --yaml --zipinfo) jc_parsers_describe=( '--acpi:`acpi` command parser' '--airport:`airport -I` command parser' @@ -126,6 +127,7 @@ _jc() { '--email-address:Email Address string parser' '--env:`env` command parser' '--file:`file` command parser' + '--findmnt:`findmnt` command parser' '--finger:`finger` command parser' '--free:`free` command parser' '--fstab:`/etc/fstab` file parser' diff --git a/docs/parsers/findmnt.md b/docs/parsers/findmnt.md new file mode 100644 index 00000000..cb13a44b --- /dev/null +++ b/docs/parsers/findmnt.md @@ -0,0 +1,116 @@ +[Home](https://kellyjonbrazil.github.io/jc/) + + +# jc.parsers.findmnt + +jc - JSON Convert `findmnt` command output parser + +<> + +Usage (cli): + + $ findmnt | jc --findmnt + +or + + $ jc findmnt + +Usage (module): + + import jc + result = jc.parse('findmnt', findmnt_command_output) + +Schema: + + [ + { + "target": string, + "source": string, + "fstype": string, + "options": [ + string + ], + "kv_options": { + "": string + } + ] + +Examples: + + $ findmnt | jc --findmnt -p + [ + { + "target": "/", + "source": "/dev/mapper/centos-root", + "fstype": "xfs", + "options": [ + "rw", + "relatime", + "seclabel", + "attr2", + "inode64", + "noquota" + ] + }, + { + "target": "/sys/fs/cgroup", + "source": "tmpfs", + "fstype": "tmpfs", + "options": [ + "ro", + "nosuid", + "nodev", + "noexec", + "seclabel" + ], + "kv_options": { + "mode": "755" + } + }, + ... + ] + + + $ findmnt | jc --findmnt -p -r + [ + { + "target": "/", + "source": "/dev/mapper/centos-root", + "fstype": "xfs", + "options": "rw,relatime,seclabel,attr2,inode64,noquota" + }, + { + "target": "/sys/fs/cgroup", + "source": "tmpfs", + "fstype": "tmpfs", + "options": "ro,nosuid,nodev,noexec,seclabel,mode=755" + }, + ... + ] + + + +### parse + +```python +def parse(data: str, + raw: bool = False, + quiet: bool = False) -> List[JSONDictType] +``` + +Main text parsing function + +Parameters: + + data: (string) text data to parse + raw: (boolean) unprocessed output if True + quiet: (boolean) suppress warning messages if True + +Returns: + + List of Dictionaries. Raw or processed structured data. + +### Parser Information +Compatibility: linux + +Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/jc/parsers/findmnt.py b/jc/parsers/findmnt.py index 04030f8e..65d38c44 100644 --- a/jc/parsers/findmnt.py +++ b/jc/parsers/findmnt.py @@ -19,19 +19,69 @@ Schema: [ { - "findmnt": string, - "bar": boolean, - "baz": integer - } + "target": string, + "source": string, + "fstype": string, + "options": [ + string + ], + "kv_options": { + "": string + } ] Examples: $ findmnt | jc --findmnt -p - [] + [ + { + "target": "/", + "source": "/dev/mapper/centos-root", + "fstype": "xfs", + "options": [ + "rw", + "relatime", + "seclabel", + "attr2", + "inode64", + "noquota" + ] + }, + { + "target": "/sys/fs/cgroup", + "source": "tmpfs", + "fstype": "tmpfs", + "options": [ + "ro", + "nosuid", + "nodev", + "noexec", + "seclabel" + ], + "kv_options": { + "mode": "755" + } + }, + ... + ] + $ findmnt | jc --findmnt -p -r - [] + [ + { + "target": "/", + "source": "/dev/mapper/centos-root", + "fstype": "xfs", + "options": "rw,relatime,seclabel,attr2,inode64,noquota" + }, + { + "target": "/sys/fs/cgroup", + "source": "tmpfs", + "fstype": "tmpfs", + "options": "ro,nosuid,nodev,noexec,seclabel,mode=755" + }, + ... + ] """ import re from typing import List, Dict diff --git a/man/jc.1 b/man/jc.1 index 573c4311..2c48cf42 100644 --- a/man/jc.1 +++ b/man/jc.1 @@ -1,4 +1,4 @@ -.TH jc 1 2022-10-31 1.22.2 "JSON Convert" +.TH jc 1 2022-11-01 1.22.2 "JSON Convert" .SH NAME \fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types, and strings .SH SYNOPSIS @@ -160,6 +160,11 @@ Email Address string parser \fB--file\fP `file` command parser +.TP +.B +\fB--findmnt\fP +`findmnt` command parser + .TP .B \fB--finger\fP diff --git a/tests/fixtures/centos-7.7/findmnt.json b/tests/fixtures/centos-7.7/findmnt.json new file mode 100644 index 00000000..850fea95 --- /dev/null +++ b/tests/fixtures/centos-7.7/findmnt.json @@ -0,0 +1 @@ +[{"target":"/","source":"/dev/mapper/centos-root","fstype":"xfs","options":["rw","relatime","seclabel","attr2","inode64","noquota"]},{"target":"/sys","source":"sysfs","fstype":"sysfs","options":["rw","nosuid","nodev","noexec","relatime","seclabel"]},{"target":"/sys/kernel/security","source":"securityfs","fstype":"securityfs","options":["rw","nosuid","nodev","noexec","relatime"]},{"target":"/sys/fs/cgroup","source":"tmpfs","fstype":"tmpfs","options":["ro","nosuid","nodev","noexec","seclabel"],"kv_options":{"mode":"755"}},{"target":"/sys/fs/cgroup/systemd","source":"cgroup","fstype":"cgroup","options":["rw","nosuid","nodev","noexec","relatime","seclabel","xattr"],"kv_options":{"release_agent":"/usr/lib/systemd/systemd-cgroups-agent","name":"systemd"}},{"target":"/sys/fs/cgroup/net_cls,net_prio","source":"cgroup","fstype":"cgroup","options":["rw","nosuid","nodev","noexec","relatime","seclabel","net_prio","net_cls"]},{"target":"/sys/fs/cgroup/blkio","source":"cgroup","fstype":"cgroup","options":["rw","nosuid","nodev","noexec","relatime","seclabel","blkio"]},{"target":"/sys/fs/cgroup/devices","source":"cgroup","fstype":"cgroup","options":["rw","nosuid","nodev","noexec","relatime","seclabel","devices"]},{"target":"/sys/fs/cgroup/hugetlb","source":"cgroup","fstype":"cgroup","options":["rw","nosuid","nodev","noexec","relatime","seclabel","hugetlb"]},{"target":"/sys/fs/cgroup/cpuset","source":"cgroup","fstype":"cgroup","options":["rw","nosuid","nodev","noexec","relatime","seclabel","cpuset"]},{"target":"/sys/fs/cgroup/cpu,cpuacct","source":"cgroup","fstype":"cgroup","options":["rw","nosuid","nodev","noexec","relatime","seclabel","cpuacct","cpu"]},{"target":"/sys/fs/cgroup/memory","source":"cgroup","fstype":"cgroup","options":["rw","nosuid","nodev","noexec","relatime","seclabel","memory"]},{"target":"/sys/fs/cgroup/perf_event","source":"cgroup","fstype":"cgroup","options":["rw","nosuid","nodev","noexec","relatime","seclabel","perf_event"]},{"target":"/sys/fs/cgroup/freezer","source":"cgroup","fstype":"cgroup","options":["rw","nosuid","nodev","noexec","relatime","seclabel","freezer"]},{"target":"/sys/fs/cgroup/pids","source":"cgroup","fstype":"cgroup","options":["rw","nosuid","nodev","noexec","relatime","seclabel","pids"]},{"target":"/sys/fs/pstore","source":"pstore","fstype":"pstore","options":["rw","nosuid","nodev","noexec","relatime"]},{"target":"/sys/kernel/config","source":"configfs","fstype":"configfs","options":["rw","relatime"]},{"target":"/sys/fs/selinux","source":"selinuxfs","fstype":"selinuxfs","options":["rw","relatime"]},{"target":"/sys/kernel/debug","source":"debugfs","fstype":"debugfs","options":["rw","relatime"]},{"target":"/proc","source":"proc","fstype":"proc","options":["rw","nosuid","nodev","noexec","relatime"]},{"target":"/proc/sys/fs/binfmt_misc","source":"systemd-1","fstype":"autofs","options":["rw","relatime","direct"],"kv_options":{"fd":"36","pgrp":"1","timeout":"0","minproto":"5","maxproto":"5","pipe_ino":"13995"}},{"target":"/dev","source":"devtmpfs","fstype":"devtmpfs","options":["rw","nosuid","seclabel"],"kv_options":{"size":"1918816k","nr_inodes":"479704","mode":"755"}},{"target":"/dev/shm","source":"tmpfs","fstype":"tmpfs","options":["rw","nosuid","nodev","seclabel"]},{"target":"/dev/pts","source":"devpts","fstype":"devpts","options":["rw","nosuid","noexec","relatime","seclabel"],"kv_options":{"gid":"5","mode":"620","ptmxmode":"000"}},{"target":"/dev/mqueue","source":"mqueue","fstype":"mqueue","options":["rw","relatime","seclabel"]},{"target":"/dev/hugepages","source":"hugetlbfs","fstype":"hugetlbfs","options":["rw","relatime","seclabel"]},{"target":"/run","source":"tmpfs","fstype":"tmpfs","options":["rw","nosuid","nodev","seclabel"],"kv_options":{"mode":"755"}},{"target":"/run/user/0","source":"tmpfs","fstype":"tmpfs","options":["rw","nosuid","nodev","relatime","seclabel"],"kv_options":{"size":"386136k","mode":"700"}},{"target":"/run/user/1000","source":"tmpfs","fstype":"tmpfs","options":["rw","nosuid","nodev","relatime","seclabel"],"kv_options":{"size":"386136k","mode":"700","uid":"1000","gid":"1000"}},{"target":"/boot","source":"/dev/sda1","fstype":"xfs","options":["rw","relatime","seclabel","attr2","inode64","noquota"]},{"target":"/var/lib/docker/containers","source":"/dev/mapper/centos-root[/var/lib/docker/containers]","fstype":"xfs","options":["rw","relatime","seclabel","attr2","inode64","noquota"]},{"target":"/var/lib/docker/overlay2","source":"/dev/mapper/centos-root[/var/lib/docker/overlay2]","fstype":"xfs","options":["rw","relatime","seclabel","attr2","inode64","noquota"]}] diff --git a/tests/test_findmnt.py b/tests/test_findmnt.py new file mode 100644 index 00000000..2032c3b7 --- /dev/null +++ b/tests/test_findmnt.py @@ -0,0 +1,44 @@ +import os +import unittest +import json +from typing import Dict +import jc.parsers.findmnt + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class MyTests(unittest.TestCase): + f_in: Dict = {} + f_json: Dict = {} + + @classmethod + def setUpClass(cls): + fixtures = { + 'centos_7_7_findmnt': ( + 'fixtures/centos-7.7/findmnt.out', + 'fixtures/centos-7.7/findmnt.json') + } + + for file, filepaths in fixtures.items(): + with open(os.path.join(THIS_DIR, filepaths[0]), 'r', encoding='utf-8') as a, \ + open(os.path.join(THIS_DIR, filepaths[1]), 'r', encoding='utf-8') as b: + cls.f_in[file] = a.read() + cls.f_json[file] = json.loads(b.read()) + + + def test_findmnt_nodata(self): + """ + Test 'findmnt' with no data + """ + self.assertEqual(jc.parsers.findmnt.parse('', quiet=True), []) + + def test_findmnt_centos_7_7(self): + """ + Test 'findmnt' on Centos 7.7 + """ + self.assertEqual(jc.parsers.findmnt.parse(self.f_in['centos_7_7_findmnt'], quiet=True), + self.f_json['centos_7_7_findmnt']) + + +if __name__ == '__main__': + unittest.main()