Skip to content

Commit

Permalink
unit tests: add tests for get_mntpoint_from_target
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Lichen Liu <[email protected]>
  • Loading branch information
licliu committed Oct 9, 2024
1 parent 1322d57 commit ad74585
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions spec/kdump-lib-initramfs_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ad74585

Please sign in to comment.