unit tests: Fix parse_config test case

The test case for parse_config creates a default kdump.conf in the pwd.
This fails when the pwd is read only. Thus move the default kdump.conf
to /tmp just like it is done for the "bad" kdump.conf. This also allows
to reuse the temporary file used for the "bad" case.

Signed-off-by: Philipp Rudo <prudo@redhat.com>
This commit is contained in:
Philipp Rudo 2023-09-06 10:49:49 +02:00 committed by Coiby Xu
parent 00c37d8c2c
commit 2f52973feb

View File

@ -173,16 +173,14 @@ Describe 'kdumpctl'
End End
Describe 'parse_config()' Describe 'parse_config()'
bad_kdump_conf=$(mktemp -t bad_kdump_conf.XXXXXXXXXX) KDUMP_CONFIG_FILE=$(mktemp -t kdump_conf.XXXXXXXXXX)
cleanup() { cleanup() {
rm -f "$bad_kdump_conf" rm -f "$KDUMP_CONFIG_FILE"
rm -f kdump.conf
} }
AfterAll 'cleanup' AfterAll 'cleanup'
It 'should not be happy with unkown option in kdump.conf' It 'should not be happy with unkown option in kdump.conf'
KDUMP_CONFIG_FILE="$bad_kdump_conf" echo blabla > "$KDUMP_CONFIG_FILE"
echo blabla > "$bad_kdump_conf"
When call parse_config When call parse_config
The status should be failure The status should be failure
The stderr should include 'Invalid kdump config option blabla' The stderr should include 'Invalid kdump config option blabla'
@ -191,10 +189,7 @@ Describe 'kdumpctl'
Parameters:value aarch64 ppc64le s390x x86_64 Parameters:value aarch64 ppc64le s390x x86_64
It 'should be happy with the default kdump.conf' It 'should be happy with the default kdump.conf'
./gen-kdump-conf.sh "$1" > kdump.conf ./gen-kdump-conf.sh "$1" > "$KDUMP_CONFIG_FILE"
# shellcheck disable=SC2034
# override the KDUMP_CONFIG_FILE variable
KDUMP_CONFIG_FILE=./kdump.conf
When call parse_config When call parse_config
The status should be success The status should be success
End End