From: Matthias Kruk Date: Fri, 18 Jun 2021 23:52:29 +0000 (+0900) Subject: test/ipc: Add test cases for ipc_msg_* functions X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=2ad47918fe152220f519032625eacd40a6b964ba;p=toolbox test/ipc: Add test cases for ipc_msg_* functions This commit adds test cases to ensure that ipc_msg_* functions work as intended. The following functions are covered by the test cases. - ipc_msg_get_version() - ipc_msg_get_source() - ipc_msg_get_destination() - ipc_msg_get_user() - ipc_msg_get_timestamp() - ipc_msg_get_data() - ipc_msg_get_signer_name() - ipc_msg_get_signer_email() - ipc_msg_get_signer_key() --- diff --git a/test/ipc_spec.sh b/test/ipc_spec.sh index 0e7ccad..d3c182a 100644 --- a/test/ipc_spec.sh +++ b/test/ipc_spec.sh @@ -343,4 +343,163 @@ EOF The status should equal 0 End + It "_ipc_msg_new()/ipc_msg_get_version() sets/gets the correct version" + _test_ipc_msg_new_version() { + local msg + + if ! msg=$(_ipc_msg_new "from" "to" "data"); then + return 1 + fi + + ipc_msg_get_version "$msg" + } + + When call _test_ipc_msg_new_version + The status should equal 0 + The stdout should equal "$__ipc_version" + End + + It "_ipc_msg_new()/ipc_msg_get_user() sets/gets the correct user" + + _test_ipc_msg_new_user() { + local msg + + msg=$(_ipc_msg_new "from" "to" "data") + + ipc_msg_get_user "$msg" + } + + When call _test_ipc_msg_new_user + The status should equal 0 + The stdout should equal "$USER" + End + + It "_ipc_msg_new()/ipc_msg_get_timestamp() sets/gets the correct timestamp" + _test_ipc_msg_new_timestamp() { + local before + local after + local msg + local timestamp + + before=$(date +"%s") + msg=$(_ipc_msg_new "from" "to" "data") + after=$(date +"%s") + + timestamp=$(ipc_msg_get_timestamp "$msg") + + if ! (( before <= timestamp )); then + return 1 + fi + + if ! (( after >= timestamp )); then + return 1 + fi + + return 0 + } + + When call _test_ipc_msg_new_timestamp + The status should equal 0 + End + + It "_ipc_msg_new()/ipc_msg_get_source() sets/gets the correct source" + _test_ipc_msg_new_source() { + local msg + + if ! msg=$(_ipc_msg_new "from" "to" "data"); then + return 1 + fi + + ipc_msg_get_source "$msg" + } + + When call _test_ipc_msg_new_source + The status should equal 0 + The stdout should equal "from" + End + + It "_ipc_msg_new()/ipc_msg_get_destination() sets/gets the correct destination" + _test_ipc_msg_new_destination() { + local msg + + if ! msg=$(_ipc_msg_new "from" "to" "data"); then + return 1 + fi + + ipc_msg_get_destination "$msg" + } + + When call _test_ipc_msg_new_destination + The status should equal 0 + The stdout should equal "to" + End + + It "_ipc_msg_new()/ipc_msg_get_data() sets/gets the correct data" + _test_ipc_msg_new_data() { + local msg + + if ! msg=$(_ipc_msg_new "from" "to" "data"); then + return 1 + fi + + ipc_msg_get_data "$msg" + } + + When call _test_ipc_msg_new_data + The status should equal 0 + The stdout should equal "data" + End + + It "ipc_msg_get_signer_name() returns the correct name" + _test_ipc_msg_get_signer_name() { + local msg + + if ! msg=$(_ipc_msg_new "from" "to" "data"); then + return 1 + fi + + ipc_msg_get_signer_name "$msg" + } + + When call _test_ipc_msg_get_signer_name + The status should equal 0 + The stdout should equal "Toolbox Test (Test)" + End + + It "ipc_msg_get_signer_email() returns the correct email" + _test_ipc_msg_get_signer_email() { + local msg + + if ! msg=$(_ipc_msg_new "from" "to" "data"); then + return 1 + fi + + ipc_msg_get_signer_email "$msg" + } + + When call _test_ipc_msg_get_signer_email + The status should equal 0 + The stdout should equal "test@m10k.eu" + End + + It "ipc_msg_get_signer_key() returns the correct key" + _test_ipc_msg_get_signer_key() { + local msg + local key + + if ! msg=$(_ipc_msg_new "from" "to" "data"); then + return 1 + fi + + if ! key=$(ipc_msg_get_signer_key "$msg"); then + return 1 + fi + + gpg --armor --export --local-user "$key" + } + + When call _test_ipc_msg_get_signer_key + The status should equal 0 + The stdout should start with "-----BEGIN PGP PUBLIC KEY BLOCK-----" + End End