From 58dbc64e88f6953b54d2646c0032e34deb7eb331 Mon Sep 17 00:00:00 2001 From: Lichen Liu Date: Wed, 9 Oct 2024 11:48:46 +0800 Subject: [PATCH] unit tests: add tests for get_mntpoint_from_target get_mntpoint_from_target was rewritten to handle bind mounts. findmnt uses square brackets to denote the fsroot, but square brackets are also used for normal purposes, such as ipv6 addresses, and dirnames can contain square brackets, too. Suggested-by: Coiby Xu Signed-off-by: Lichen Liu --- spec/kdump-lib-initramfs_spec.sh | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/spec/kdump-lib-initramfs_spec.sh b/spec/kdump-lib-initramfs_spec.sh index dc507930..2cb85bb3 100644 --- a/spec/kdump-lib-initramfs_spec.sh +++ b/spec/kdump-lib-initramfs_spec.sh @@ -38,4 +38,54 @@ Describe 'kdump-lib-initramfs' End + Describe 'Test get_mntpoint_from_target' + findmnt() { + if [[ "$7" == 'eng.redhat.com:/srv/[nfs]' ]]; then + if [[ "$8" == "-f" ]]; then + printf '/mnt\n' + else + printf '/mnt %s\n' "$7" + fi + elif [[ "$7" == '[2620:52:0:a1:217:38ff:fe01:131]:/srv/[nfs]' ]]; then + if [[ "$8" == "-f" ]]; then + printf '/mnt\n' + else + printf '/mnt %s\n' "$7" + fi + elif [[ "$7" == '/dev/mapper/rhel[disk]' ]]; then + if [[ "$8" == "-f" ]]; then + printf '/\n' + else + printf '/ %s\n' "$7" + fi + elif [[ "$7" == '/dev/vda4' ]]; then + if [[ "$8" == "-f" ]]; then + printf '/var\n' + else + printf '/var %s[/ostree/deploy/default/var]\n/sysroot %s\n' "$7" "$7" + fi + fi + } + + Context 'Given different cases' + # Test the following cases: + # - IPv6 NFS target + # - IPv6 NFS target also contain '[' in the export + # - local dumping target that has '[' in the name + # - has bind mint + Parameters + 'eng.redhat.com:/srv/[nfs]' '/mnt' + '[2620:52:0:a1:217:38ff:fe01:131]:/srv/[nfs]' '/mnt' + '/dev/mapper/rhel[disk]' '/' + '/dev/vda4' '/sysroot' + End + + It 'should handle all cases correctly' + When call get_mntpoint_from_target "$1" + The output should equal "$2" + End + End + + End + End