unit tests: add tests for _{update,read}_kernel_arg_in_grub_etc_default in kdumpctl
Reviewed-by: Philipp Rudo <prudo@redhat.com> Signed-off-by: Coiby Xu <coxu@redhat.com>
This commit is contained in:
parent
6506bd9b1b
commit
ea8b06df83
@ -107,4 +107,71 @@ Describe 'kdumpctl'
|
||||
End
|
||||
End
|
||||
|
||||
Describe '_update_kernel_arg_in_grub_etc_default()'
|
||||
GRUB_ETC_DEFAULT=/tmp/default_grub
|
||||
|
||||
cleanup() {
|
||||
rm -rf "$GRUB_ETC_DEFAULT"
|
||||
}
|
||||
AfterAll 'cleanup'
|
||||
|
||||
Context 'when the given parameter is in different positions'
|
||||
Parameters
|
||||
"crashkernel=222M fadump=on rhgb quiet" crashkernel 333M
|
||||
" fadump=on crashkernel=222M rhgb quiet" crashkernel 333M
|
||||
"fadump=on rhgb quiet crashkernel=222M" crashkernel 333M
|
||||
"fadump=on rhgb quiet" crashkernel 333M
|
||||
"fadump=on foo=bar1 rhgb quiet" foo bar2
|
||||
End
|
||||
|
||||
It 'should update the kernel parameter correctly'
|
||||
echo 'GRUB_CMDLINE_LINUX="'"$1"'"' >$GRUB_ETC_DEFAULT
|
||||
When call _update_kernel_arg_in_grub_etc_default "$2" "$3"
|
||||
# the updated kernel parameter should appear in the end
|
||||
The contents of file $GRUB_ETC_DEFAULT should include "$2=$3\""
|
||||
End
|
||||
End
|
||||
|
||||
It 'should only update the given parameter and not update the parameter that has the given parameter as suffix'
|
||||
echo 'GRUB_CMDLINE_LINUX="fadump=on rhgb quiet ckcrashkernel=222M"' >$GRUB_ETC_DEFAULT
|
||||
_ck_val=1G-4G:192M,4G-64G:256M,64G-102400T:512M
|
||||
When call _update_kernel_arg_in_grub_etc_default crashkernel "$_ck_val"
|
||||
The contents of file $GRUB_ETC_DEFAULT should include "crashkernel=$_ck_val\""
|
||||
The contents of file $GRUB_ETC_DEFAULT should include "ckcrashkernel=222M"
|
||||
End
|
||||
|
||||
It 'should be able to handle the cases of there are multiple crashkernel entries'
|
||||
echo 'GRUB_CMDLINE_LINUX="fadump=on rhgb quiet crashkernel=101M crashkernel=222M"' >$GRUB_ETC_DEFAULT
|
||||
_ck_val=1G-4G:192M,4G-64G:256M,64G-102400T:512M
|
||||
When call _update_kernel_arg_in_grub_etc_default crashkernel "$_ck_val"
|
||||
The contents of file $GRUB_ETC_DEFAULT should include "crashkernel=$_ck_val\""
|
||||
The contents of file $GRUB_ETC_DEFAULT should not include "crashkernel=222M"
|
||||
End
|
||||
|
||||
Context 'when it removes a kernel parameter'
|
||||
|
||||
It 'should remove all values for given arg'
|
||||
echo 'GRUB_CMDLINE_LINUX="crashkernel=33M crashkernel=11M fadump=on crashkernel=222M"' >$GRUB_ETC_DEFAULT
|
||||
When call _update_kernel_arg_in_grub_etc_default crashkernel
|
||||
The contents of file $GRUB_ETC_DEFAULT should equal 'GRUB_CMDLINE_LINUX="fadump=on"'
|
||||
End
|
||||
|
||||
It 'should not remove args that have the given arg as suffix'
|
||||
echo 'GRUB_CMDLINE_LINUX="ckcrashkernel=33M crashkernel=11M ckcrashkernel=222M"' >$GRUB_ETC_DEFAULT
|
||||
When call _update_kernel_arg_in_grub_etc_default crashkernel
|
||||
The contents of file $GRUB_ETC_DEFAULT should equal 'GRUB_CMDLINE_LINUX="ckcrashkernel=33M ckcrashkernel=222M"'
|
||||
End
|
||||
End
|
||||
|
||||
End
|
||||
|
||||
Describe '_read_kernel_arg_in_grub_etc_default()'
|
||||
GRUB_ETC_DEFAULT=/tmp/default_grub
|
||||
It 'should read the value for given arg'
|
||||
echo 'GRUB_CMDLINE_LINUX="crashkernel=33M crashkernel=11M ckcrashkernel=222M"' >$GRUB_ETC_DEFAULT
|
||||
When call _read_kernel_arg_in_grub_etc_default crashkernel
|
||||
The output should equal '11M'
|
||||
End
|
||||
End
|
||||
|
||||
End
|
||||
|
Loading…
Reference in New Issue
Block a user