Skip to content

Commit 38c1069

Browse files
committed
Update alert test scripts to include ALERT_DEDUPLICATION_ENABLED variable
- Added the ALERT_DEDUPLICATION_ENABLED environment variable to both test_sendAlert_additional.sh and test_sendAlert_third.sh for better configuration management. - Refactored assertions in the teardown functions to use a more concise syntax for checking non-empty values. - Improved HTML and JSON formatting checks to enhance test reliability and clarity.
1 parent df7200f commit 38c1069

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

tests/unit/alerts/test_sendAlert_additional.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ setup() {
3939
export SEND_ALERT_EMAIL="false"
4040
export SLACK_ENABLED="false"
4141
export ADMIN_EMAIL="test@example.com"
42+
export ALERT_DEDUPLICATION_ENABLED="false"
4243

4344
init_logging "${LOG_DIR}/test_sendAlert_additional.log" "test_sendAlert_additional"
4445
init_alerting
@@ -55,15 +56,15 @@ teardown() {
5556
local html
5657
html=$(format_html "TEST_COMPONENT" "warning" "test_alert" "Test message")
5758

58-
assert [[ -n "${html}" ]]
59+
[ -n "${html}" ] || return 1
5960
assert echo "${html}" | grep -q "warning"
6061
}
6162

6263
@test "format_alert_html handles info level" {
6364
local html
6465
html=$(format_html "TEST_COMPONENT" "info" "test_alert" "Test message")
6566

66-
assert [[ -n "${html}" ]]
67+
[ -n "${html}" ] || return 1
6768
assert echo "${html}" | grep -q "info"
6869
}
6970

@@ -74,7 +75,7 @@ teardown() {
7475
local json
7576
json=$(format_json "TEST_COMPONENT" "critical" "test_alert" "Test message" '{"key":"value"}')
7677

77-
assert [[ -n "${json}" ]]
78+
[ -n "${json}" ] || return 1
7879
assert echo "${json}" | grep -q "key"
7980
}
8081

@@ -133,7 +134,9 @@ teardown() {
133134
html=$(format_html "TEST_COMPONENT" "critical" "test_alert" "Test <script>alert('xss')</script> message")
134135

135136
# Should not contain unescaped script tags
136-
assert ! echo "${html}" | grep -q "<script>"
137+
if echo "${html}" | grep -q "<script>"; then
138+
return 1
139+
fi
137140
}
138141

139142
##
@@ -143,7 +146,7 @@ teardown() {
143146
local json
144147
json=$(format_json "TEST_COMPONENT" "critical" "test_alert" "Test message" "")
145148

146-
assert [[ -n "${json}" ]]
149+
[ -n "${json}" ] || return 1
147150
}
148151

149152
##
@@ -152,6 +155,7 @@ teardown() {
152155
@test "main handles --slack-channel option" {
153156
export SLACK_ENABLED="true"
154157
export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/TEST/TEST/TEST"
158+
export ALERT_DEDUPLICATION_ENABLED="false"
155159

156160
# Mock send_alert
157161
# shellcheck disable=SC2317

tests/unit/alerts/test_sendAlert_third.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ setup() {
2727
export LOG_DIR="${TEST_LOG_DIR}"
2828
export SEND_ALERT_EMAIL="false"
2929
export SLACK_ENABLED="false"
30+
export ALERT_DEDUPLICATION_ENABLED="false"
3031
init_logging "${LOG_DIR}/test_sendAlert_third.log" "test_sendAlert_third"
3132
init_alerting
3233
}
@@ -116,6 +117,7 @@ teardown() {
116117
##
117118
@test "main handles --slack option" {
118119
export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/TEST/TEST/TEST"
120+
export ALERT_DEDUPLICATION_ENABLED="false"
119121

120122
# Mock enhanced_send_alert
121123
# shellcheck disable=SC2317

0 commit comments

Comments
 (0)