On Mon, Feb 28, 2022 at 03:41:09PM +0800, Tao Liu wrote:
On Mon, Feb 21, 2022 at 8:58 PM Coiby Xu <coxu(a)redhat.com>
wrote:
>
> 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
>
> Signed-off-by: Coiby Xu <coxu(a)redhat.com>
> ---
> .shellspec | 0
> spec/kdumpctl_general_spec.sh | 46 +++++++++++++++++++++++++++++++++++
> 2 files changed, 46 insertions(+)
> create mode 100644 .shellspec
> create mode 100644 spec/kdumpctl_general_spec.sh
>
> diff --git a/.shellspec b/.shellspec
> new file mode 100644
> index 0000000..e69de29
> diff --git a/spec/kdumpctl_general_spec.sh b/spec/kdumpctl_general_spec.sh
> new file mode 100644
> index 0000000..8c7ec01
> --- /dev/null
> +++ b/spec/kdumpctl_general_spec.sh
> @@ -0,0 +1,46 @@
> +#!/bin/bash
> +Describe 'kdumpctl'
> + Include ./kdumpctl
> +
> + Describe 'get_grub_kernel_boot_parameter()'
> + grubby() {
> + %text
> + #|index=1
> + #|kernel="/boot/vmlinuz-5.14.14-200.fc34.x86_64"
> + #|args="crashkernel=11M nvidia-drm.modeset=1
crashkernel=100M ro rhgb quiet crcrashkernel=200M
crashkernel=32T-64T:128G,64T-102400T:180G fadump=on"
> + #|root="UUID=45fdf703-3966-401b-b8f7-cf056affd2b0"
> + }
> + Context "when given a kernel parameter in different
positions"
> + # Test the following cases:
> + # - the kernel parameter in the end
> + # - the kernel parameter in the first
> + # - the kernel parameter is crashkernel (suffix of
crcrashkernel)
> + # - the kernel parameter that does not exist
> + # - the kernel parameter doesn't have a value
> + Parameters
> + # parameter answer
> + fadump on
> + nvidia-drm.modeset 1
> + crashkernel 32T-64T:128G,64T-102400T:180G
> + aaaa ""
> + ro ""
> + End
> +
> + It 'should retrieve the value succesfully'
> + When call get_grub_kernel_boot_parameter
/boot/vmlinuz "$2"
Can we change the /boot/vmlinuz string into variable and use it like:
DUMMY_PARAM=/boot/vmlinuz
When call get_grub_kernel_boot_parameter $DUMMY_PARAM "$2"
"/boot/vmlinuz" is a little misleading to me, because I didn't have
such a file on my local
drive. As far as I understand the code, the previous grubby() function
just mock up the
grubby cmdline tool. So any string other than "ALL" as the 1st param given to
get_grub_kernel_boot_parameter, the grubby will always output the mocked text,
so "DUMMY_PARAM" is more likely to represent the idea.
> + The output should equal "$3"
> + End
> + End
> +
> + It 'should retrive the last value if multiple
<parameter=value> entries exist'
> + When call get_grub_kernel_boot_parameter /boot/vmlinuz
crashkernel
Same issue here.
Applied to v1. Thanks for the suggestion!
> + The output should equal
'32T-64T:128G,64T-102400T:180G'
> + End
> +
> + It 'should fail when called with kernel_path=ALL'
> + When call get_grub_kernel_boot_parameter ALL ro
> + The status should be failure
> + The error should include "kernel_path=ALL invalid"
> + End
> + End
> +End
> --
> 2.34.1
> _______________________________________________
> kexec mailing list -- kexec(a)lists.fedoraproject.org
> To unsubscribe send an email to kexec-leave(a)lists.fedoraproject.org
> Fedora Code of Conduct:
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
> List Guidelines:
https://fedoraproject.org/wiki/Mailing_list_guidelines
> List Archives:
https://lists.fedoraproject.org/archives/list/kexec@lists.fedoraproject.org
> Do not reply to spam on the list, report it:
https://pagure.io/fedora-infrastructure
--
Best regards,
Coiby