From fa1f3b005e1c92ed7c13d5fbf51e33cb170ffabd Mon Sep 17 00:00:00 2001 From: georglauterbach <44545919+georglauterbach@users.noreply.github.com> Date: Tue, 23 Jan 2024 19:30:16 +0100 Subject: [PATCH] added explicit `_regexp` filters for logs --- test/helper/log_and_filtering.bash | 26 ++++++++++++++++--- .../parallel/set1/spam_virus/rspamd_full.bats | 2 +- test/tests/serial/tests.bats | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/test/helper/log_and_filtering.bash b/test/helper/log_and_filtering.bash index dec46cfe..68856700 100644 --- a/test/helper/log_and_filtering.bash +++ b/test/helper/log_and_filtering.bash @@ -45,9 +45,8 @@ function _show_complete_mail_log() { # # @param ${1} = service name # @param ${2} = string to filter by -# @param ${3} = container name [OPTIONAL] function _service_log_should_contain_string() { - _filter_service_log "${@}" + _filter_service_log "${1}" "${2}" --fixed-strings assert_success } @@ -55,9 +54,28 @@ function _service_log_should_contain_string() { # # @param ${1} = service name # @param ${2} = string to filter by -# @param ${3} = container name [OPTIONAL] function _service_log_should_not_contain_string() { - _filter_service_log "${@}" + _filter_service_log "${1}" "${2}" --fixed-strings + assert_failure +} + +# Like `_filter_service_log` but asserts that the string was found. Uses regular expressions +# under the hood for pattern matching. +# +# @param ${1} = service name +# @param ${2} = regular expression to filter by +function _service_log_should_contain_string_regexp() { + _filter_service_log "${1}" "${2}" --extended-regexp + assert_success +} + +# Like `_filter_service_log` but asserts that the string was not found. Uses regular expressions +# under the hood for pattern matching. +# +# @param ${1} = service name +# @param ${2} = regular expression to filter by +function _service_log_should_not_contain_string_regexp() { + _filter_service_log "${1}" "${2}" --extended-regexp assert_failure } diff --git a/test/tests/parallel/set1/spam_virus/rspamd_full.bats b/test/tests/parallel/set1/spam_virus/rspamd_full.bats index 7b53b017..9e6d6222 100644 --- a/test/tests/parallel/set1/spam_virus/rspamd_full.bats +++ b/test/tests/parallel/set1/spam_virus/rspamd_full.bats @@ -93,7 +93,7 @@ function teardown_file() { _default_teardown ; } } @test 'service log exist and contains proper content' { - _service_log_should_contain_string 'rspamd' 'rspamd .* is loading configuration' + _service_log_should_contain_string_regexp 'rspamd' 'rspamd .* is loading configuration' _service_log_should_contain_string 'rspamd' 'lua module clickhouse is disabled in the configuration' _service_log_should_contain_string 'rspamd' 'lua module elastic is disabled in the configuration' _service_log_should_contain_string 'rspamd' 'lua module neural is disabled in the configuration' diff --git a/test/tests/serial/tests.bats b/test/tests/serial/tests.bats index dcc1bb42..eff151df 100644 --- a/test/tests/serial/tests.bats +++ b/test/tests/serial/tests.bats @@ -205,7 +205,7 @@ function teardown_file() { _default_teardown ; } } @test "system: amavis decoders installed and available" { - _service_log_should_contain_string 'mail' '.*(Internal decoder|Found decoder) for\s+\..*' '-E' + _service_log_should_contain_string_regexp 'mail' '.*(Internal decoder|Found decoder) for\s+\..*' run bash -c "grep -Eo '(mail|Z|gz|bz2|xz|lzma|lrz|lzo|lz4|rpm|cpio|tar|deb|rar|arj|arc|zoo|doc|cab|tnef|zip|kmz|7z|jar|swf|lha|iso|exe)' <<< '${output}' | sort | uniq" assert_success # Support for doc and zoo removed in buster