unit tests: add tests for kdump_get_conf_val in kdump-lib-initramfs.sh

kdump_get_conf_val allows to retrieves config value defined in
kdump.conf and it also supports sed regex like
"ext[234]\|xfs\|btrfs\|minix\|raw\|nfs\|ssh".

Reviewed-by: Philipp Rudo <prudo@redhat.com>
Signed-off-by: Coiby Xu <coxu@redhat.com>
This commit is contained in:
Coiby Xu 2022-01-06 14:24:22 +08:00
parent e00b45d75f
commit e28a1399a3
1 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,41 @@
#!/bin/bash
Describe 'kdump-lib-initramfs'
Include ./kdump-lib-initramfs.sh
Describe 'Test kdump_get_conf_val'
KDUMP_CONFIG_FILE=/tmp/kdump_shellspec_test.conf
kdump_config() {
%text
#|default shell
#|nfs my.server.com:/export/tmp # trailing comment
#| failure_action shell
#|dracut_args --omit-drivers "cfg80211 snd" --add-drivers "ext2 ext3"
#|sshkey /root/.ssh/kdump_id_rsa
#|ssh user@my.server.com
}
kdump_config >$KDUMP_CONFIG_FILE
Context 'Given different cases'
# Test the following cases:
# - there is trailing comment
# - there is space before the parameter
# - complicate value for dracut_args
# - Given two parameters, retrive one parameter that has value specified
# - Given two parameters (in reverse order), retrive one parameter that has value specified
Parameters
"#1" nfs my.server.com:/export/tmp
"#2" ssh user@my.server.com
"#3" failure_action shell
"#4" dracut_args '--omit-drivers "cfg80211 snd" --add-drivers "ext2 ext3"'
"#5" 'ssh\|aaa' user@my.server.com
"#6" 'aaa\|ssh' user@my.server.com
End
It 'should handle all cases correctly'
When call kdump_get_conf_val "$2"
The output should equal "$3"
End
End
End
End