Commit Graph

7 Commits

Author SHA1 Message Date
Coiby Xu
3d4cb38d96 unit tests: add check_config with with the default kdump.conf
This test prevents the mistake of adding an option to kdump.conf
without changing check_config as is the case with commit 73ced7f
("introduce the auto_reset_crashkernel option to kdump.conf").

Reviewed-by: Philipp Rudo <prudo@redhat.com>
Signed-off-by: Coiby Xu <coxu@redhat.com>
2022-04-14 11:45:33 +08:00
Coiby Xu
e28a1399a3 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>
2022-04-14 11:45:18 +08:00
Coiby Xu
e00b45d75f unit tests: add tests for "kdumpctl reset-crashkernel"
This commit adds a relatively thorough test suite for
kdumpctl reset-crashkernel [--fadump=[on|off|nocma]]  [--kernel=path_to_kernel] [--reboot]
as implemented in commit 140da74 ("rewrite reset_crashkernel to support
fadump and to used by RPM scriptlet").

grubby have a few options to support its own testing,
 - --no-etc-grub-update, not update /etc/default/grub
 - --bad-image-okay, don't check the validity of the image
 - --env, specify custom grub2 environment block file to avoid modifying
   the default /boot/grub2/grubenv
 - --bls-directory, specify custom BootLoaderSpec config files to avoid
   modifying the default /boot/loader/entries

So the grubby called by kdumpctl is mocked as
@grubby --grub2 --no-etc-grub-update --bad-image-okay --env=$SPEC_TEST_DIR/env_temp -b $SPEC_TEST_DIR/boot_load_entries "$@"
in the tests. To be able to call the actual grubby in the mock function [1],
ShellSpec provides the following command
$ shellspec --gen-bin @grubby
to generate spec/support/bins/@grubby which is used to call the actual grubby.

kdumpctl has implemented its own version of updating /etc/default/grub
in _update_kernel_cmdline_in_grub_etc_default. To avoiding writing to
/etc/default/grub, this function is mocked as outputting its name and
received arguments similar to python unitest's assert_called_with.

[1]  https://github.com/shellspec/shellspec#execute-the-actual-command-within-a-mock-function

Reviewed-by: Philipp Rudo <prudo@redhat.com>
Signed-off-by: Coiby Xu <coxu@redhat.com>
2022-04-14 11:45:08 +08:00
Coiby Xu
ea8b06df83 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>
2022-04-14 11:45:01 +08:00
Coiby Xu
6506bd9b1b unit tests: add tests for kdumpctl read_proc_environ_var and _is_osbuild
AfterAll is an example group hook [1] which would be run after the group
tests are executed. Use this hook to clean up the files created by mktemp.

[1] https://github.com/shellspec/shellspec#beforeall-afterall---example-group-hook

Reviewed-by: Philipp Rudo <prudo@redhat.com>
Signed-off-by: Coiby Xu <coxu@redhat.com>
2022-04-14 11:44:54 +08:00
Coiby Xu
59386d5a8b unit tests: add tests for get_dump_mode_by_fadump_val
Reviewed-by: Philipp Rudo <prudo@redhat.com>
Signed-off-by: Coiby Xu <coxu@redhat.com>
2022-04-14 11:44:45 +08:00
Coiby Xu
93373c0406 unit tests: add tests for get_grub_kernel_boot_parameter
This test suite makes use of three features provided by ShellSpec
 - funcion-based mock [2]: mock a function by re-defining and exporting it
 - parameterized tests [3]: run multiple sets of input against the same
   test
 - %text directive [4]: similar to heredoc but free of
   the indentation issue

Note
1. Describe and Context are aliases for ExampleGroup which a block for
grouping example groups or examples [5]. Describe and Context are used to
improve readability.
2. ShellSpec requires .shellspec file.

[1] https://github.com/dodie/testing-in-bash#detailed-comparision
[2] https://github.com/shellspec/shellspec#function-based-mock
[3] https://github.com/shellspec/shellspec#parameters---parameterized-example
[4] https://github.com/shellspec/shellspec#text---embedded-text
[5] https://github.com/shellspec/shellspec#dsl-syntax

Reviewed-by: Philipp Rudo <prudo@redhat.com>
Signed-off-by: Coiby Xu <coxu@redhat.com>
2022-04-14 11:44:27 +08:00