From 6506bd9b1bcd4117676aaef513c144c4d81bec21 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 21 Jan 2022 15:46:40 +0800 Subject: [PATCH] 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 Signed-off-by: Coiby Xu --- spec/kdumpctl_general_spec.sh | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/spec/kdumpctl_general_spec.sh b/spec/kdumpctl_general_spec.sh index b968f74..9fbc1a0 100644 --- a/spec/kdumpctl_general_spec.sh +++ b/spec/kdumpctl_general_spec.sh @@ -70,5 +70,41 @@ Describe 'kdumpctl' End + Describe "read_proc_environ_var()" + environ_test_file=$(mktemp -t spec_test_environ_test_file.XXXXXXXXXX) + cleanup() { + rm -rf "$environ_test_file" + } + AfterAll 'cleanup' + echo -ne "container=bwrap-osbuild\x00SSH_AUTH_SOCK=/tmp/ssh-XXXXXXEbw33A/agent.1794\x00SSH_AGENT_PID=1929\x00env=test_env" >"$environ_test_file" + Parameters + container bwrap-osbuild + SSH_AUTH_SOCK /tmp/ssh-XXXXXXEbw33A/agent.1794 + env test_env + not_exist "" + End + It 'should read the environ variable value as expected' + When call read_proc_environ_var "$1" "$environ_test_file" + The output should equal "$2" + The status should be success + End + End + + Describe "_is_osbuild()" + environ_test_file=$(mktemp -t spec_test_environ_test_file.XXXXXXXXXX) + # shellcheck disable=SC2034 + # override the _OSBUILD_ENVIRON_PATH variable + _OSBUILD_ENVIRON_PATH="$environ_test_file" + Parameters + 'container=bwrap-osbuild' success + '' failure + End + It 'should be able to tell if it is the osbuild environment' + echo -ne "$1" >"$environ_test_file" + When call _is_osbuild + The status should be "$2" + The stderr should equal "" + End + End End