rcourtman
e6d07c3294
style: remove emojis from log messages
...
Replaced emoji icons with plain text for cleaner logs and cross-platform compatibility.
2025-12-13 21:29:11 +00:00
rcourtman
4f824ab148
style: Apply gofmt to 37 files
...
Standardize code formatting across test files and monitor.go.
No functional changes.
2025-12-02 17:21:48 +00:00
rcourtman
629645a2a0
test: Add UpdateStatus not found test for notifications package
2025-12-02 14:26:17 +00:00
rcourtman
89b624c731
test: Add NewNotificationQueue invalid path test for notifications package
2025-12-02 14:17:05 +00:00
rcourtman
fca712430e
test: Add singleAlertTemplate type coverage tests
...
Cover io type (formats as "I/O") and custom type (uses titleCase)
branches that were previously untested in the email template.
2025-12-02 13:45:49 +00:00
rcourtman
f4397b1512
test: Add ValidateWebhookURL edge case tests for notifications package
...
Cover empty URL, invalid scheme, missing hostname, cloud metadata
endpoints, loopback variants, and IPv6 link-local addresses.
2025-12-02 13:41:34 +00:00
rcourtman
b49a014737
test: Add sendResolvedEmail tests for notifications package
...
Add comprehensive tests for the sendResolvedEmail function covering:
- Empty alert list (returns error)
- Nil alert list (returns error)
- All nil alerts (returns error from content builder)
- Single alert (exercises email sending path)
- Multiple alerts (tests grouped notification)
- Mixed nil and valid alerts (filters correctly)
- Zero resolved time (handles gracefully)
Also improves buildResolvedNotificationContent coverage as a collateral
benefit since sendResolvedEmail calls it internally.
Coverage: sendResolvedEmail 0% → 100%
Coverage: buildResolvedNotificationContent → 100%
Coverage: notifications package 58.3% → 58.6%
2025-12-02 13:14:22 +00:00
rcourtman
d5acf4be32
test: Add performCleanup tests for notifications queue
...
Add 4 tests covering the performCleanup function:
- cleanup removes old completed entries (>7 days)
- cleanup removes old DLQ entries (>30 days)
- cleanup removes old audit logs (>30 days)
- cleanup with empty database (no panic)
performCleanup coverage: 0% → 87.0%
Notifications package: 57.3% → 58.3%
2025-12-02 12:16:55 +00:00
rcourtman
7104f76f06
test: Add GetQueue, addWebhookDelivery, GetWebhookHistory tests
...
Tests for NotificationManager accessor and helper functions.
Covers queue retrieval, webhook delivery tracking, history trimming
to max 100 entries, and copy-on-read semantics. Notifications 56.6%→57.3%.
2025-12-02 12:10:29 +00:00
rcourtman
3427aa7f01
fix: Deadlock in CancelByAlertIDs and add tests
...
Fixed deadlock where CancelByAlertIDs held nq.mu.Lock() and then called
UpdateStatus() which also tried to acquire the same lock. Now uses
direct SQL while holding the lock.
Tests added for CancelByAlertIDs:
- No matching notifications (notification stays pending)
- Matching notification cancelled
- Multiple alerts with partial match (any match cancels)
Coverage: CancelByAlertIDs 65.7% -> 81.1%
2025-12-02 10:40:07 +00:00
rcourtman
3000c3be87
test: Add queue IncrementAttempt and GetQueueStats tests
...
Coverage improvements:
- IncrementAttempt: 0% -> 85.7%
- GetQueueStats: 0% -> 87.5%
Tests verify attempt counter increments correctly and queue stats
aggregate notification counts by status.
2025-12-02 10:31:00 +00:00
rcourtman
0c9c99a700
test: Add secure webhook client tests for redirect handling
...
Tests SSRF protection in webhook client:
- Redirect limit enforcement (max 3)
- Blocking redirects to private networks (10.x, 192.168.x, 172.16.x)
- Blocking redirects to link-local addresses (169.254.x)
- Allowing valid redirects to allowlisted servers
Coverage: createSecureWebhookClient 18.2% -> 100%
2025-12-02 10:26:34 +00:00
rcourtman
3a38e4abf7
test: Add sendNotificationsDirect email and apprise tests
...
Test email enabled and apprise enabled code paths.
Coverage: 66.7% → 100.0%
2025-12-02 03:08:35 +00:00
rcourtman
a1fd8420e4
test: Add scanNotification DLQ timestamp test
...
Test scanNotification with CompletedAt and LastAttempt populated
via DLQ path. Coverage: 61.9% → 81.0%
2025-12-02 03:04:37 +00:00
rcourtman
20e3c4c718
test: Add processNotification tests for all code paths
...
Test cancelled notification, no processor, success, and failure paths.
Coverage: 50.0% → 80.0%
2025-12-02 03:01:17 +00:00
rcourtman
4765a5fa78
test: Add CancelByAlertIDs empty input and no-match tests
...
Test early return for empty alertIDs and happy path with empty queue.
Coverage: 62.9% → 65.7%
2025-12-02 02:58:10 +00:00
rcourtman
d873d68dcc
test: Add ProcessQueuedNotification error path tests
...
Cover invalid config JSON for email, webhook, and apprise types,
plus unknown notification type handling.
Coverage: 63.3% → 83.3%
2025-12-02 02:26:25 +00:00
rcourtman
5bd018277f
test: Add sendNotificationsDirect tests
...
Cover disabled paths: all channels disabled, webhook disabled,
multiple webhooks with mixed enabled state.
Coverage: 44.4% → 66.7%
2025-12-02 02:21:46 +00:00
rcourtman
251b252062
test: Add sendHTMLEmailWithError tests
...
Cover email sending paths: empty To uses From as recipient,
nil email manager creates new one, existing manager config updates.
Coverage: 57.9% → 89.5%
2025-12-02 02:19:49 +00:00
rcourtman
645173ec22
test: Add sendGroupedApprise error path tests
...
Add 3 tests for Apprise notification error handling:
- No alerts returns error
- Not enabled returns error
- Empty payload (all nil alerts) returns error
Coverage: 56.2% → 75.0%
2025-12-02 02:14:13 +00:00
rcourtman
87a184137b
test: Add DNS resolution failure test for ValidateWebhookURL
...
Tests the error path when webhook hostname cannot be resolved
(78.1% to 81.2% coverage).
2025-12-02 01:09:03 +00:00
rcourtman
4e90e6efb2
test: Add critical-only grouped alert template case
...
Test multiple critical alerts without warnings to cover the
"critical > 0" only branch in subject line generation.
Coverage: 97.7% → 100%
2025-12-02 00:40:02 +00:00
rcourtman
6c21af6e3d
test: Add edge cases for buildApprisePayload
...
- Test nil alerts in list are filtered out
- Test all-nil alert list returns empty
- Test multiple alerts changes title format
Coverage: 88.9% → 100%
2025-12-02 00:37:28 +00:00
rcourtman
eb46942a40
test: Add edge case for extractTelegramChatID URL parse error
...
Test URL with control characters triggers url.Parse error path.
Coverage: 92.9% → 100%
2025-12-02 00:31:50 +00:00
rcourtman
b326580780
test: Add edge case for NormalizeAppriseConfig low timeout
...
Test TimeoutSeconds value between 1-4 clamps to minimum of 5.
Coverage: 97.4% → 100%
2025-12-02 00:29:12 +00:00
rcourtman
c6f14b2c6e
test: Add tests for webhook template generation and bootstrap token functions
...
- Add comprehensive tests for generatePayloadFromTemplateWithService covering:
- Valid JSON template rendering
- Invalid template syntax error handling
- Template execution errors
- ntfy service (plain text, skips JSON validation)
- Various services (discord, telegram, pagerduty) JSON validation
- Template function usage (upper, title)
- Numeric and boolean values in templates
- Special characters and empty template edge cases
- Add tests for bootstrapTokenValid covering:
- Nil router handling
- Empty hash and empty token cases
- Valid token validation
- Invalid token rejection
- Whitespace trimming
- Add tests for clearBootstrapToken covering:
- Nil router safety
- Token file deletion
- Missing file handling
- Empty path handling
2025-12-01 22:07:40 +00:00
rcourtman
3cb5c8c200
test: Add tests for prepareWebhookData function
...
Covers webhook payload data preparation:
- publicURL handling with trailing slash trimming
- alert.Instance URL detection (http/https)
- Metadata extraction and copying
- Value/Threshold rounding to 1 decimal
- AckTime formatting
- CustomFields passthrough
2025-12-01 21:27:29 +00:00
rcourtman
2ec81733cb
test: Add tests for notification rate limiting and content building
...
- checkWebhookRateLimit: rate limit window, counter, per-URL isolation
- buildResolvedNotificationContent: single/multiple alerts, nil filtering,
HTML escaping, timestamp handling, optional fields
2025-12-01 21:25:02 +00:00
rcourtman
7359a9fb4d
test: Add tests for mergeNVMeTempsIntoDisks, UpdateQueueSnapshot, UpdateDeadLetterCounts, templateFuncMap
...
- mergeNVMeTempsIntoDisks: 57%→97% (14 tests covering WWN/serial/path matching, NVMe fallback)
- UpdateQueueSnapshot: 57%→100% (5 tests covering nil, gauges, stale key cleanup)
- UpdateDeadLetterCounts: 52%→100% (7 tests covering aggregation, normalization)
- templateFuncMap: 20%→100% (8 tests covering all template helper functions)
Monitoring 44.6%→45.3%, notifications 45.7%→45.9%
2025-12-01 18:14:43 +00:00
rcourtman
b444793897
test: Add tests for monitoring and notifications functions
...
- buildCephClusterModel: 0% → 100% (11 test cases)
- collectContainerRootUsage: 0% → 100% (18 test cases)
- NotificationManager getters/setters: 8 functions now tested
Overall coverage: 45.5% → 45.8%
2025-12-01 17:33:36 +00:00
rcourtman
1c36a2433f
test: Add comprehensive tests for EmailTemplate function
...
Cover both branches: single alert template (isSingle=true with 1 alert)
and grouped alert template (isSingle=false or multiple alerts). Tests
verify subject format, HTML structure, and text body generation.
Coverage improved from 66.7% to 100%.
2025-12-01 15:29:31 +00:00
rcourtman
ac74146c46
test: Add renderWebhookURL URL parsing error test
...
Add test case for malformed IPv6 URL that triggers url.Parse error.
Improves coverage from 90% to 95%. The remaining 5% is a template
Execute error path that's effectively unreachable with current types.
2025-12-01 14:57:25 +00:00
rcourtman
e57e2e696b
test: Improve coverage for security utility functions
...
- Add fmt.Stringer test cases for isEmptyInterface (80% -> 100%)
- Expand isTrustedNetwork tests with edge cases (80% -> 100%)
- Empty/invalid IP strings
- Invalid CIDR handling
- Whitespace trimming in CIDRs
- Multiple network matching
2025-12-01 14:33:31 +00:00
rcourtman
8b4d4f649e
test: Add tests for notification config copy functions
...
Tests for defensive copy functions that ensure data isolation:
- copyEmailConfig: copies email config with slice independence
- copyWebhookConfigs: deep copies webhooks including maps
- copyAppriseConfig: copies apprise config with slice independence
- buildNotificationTestAlert: validates test alert structure
Tests verify that modifying copies doesn't affect originals,
critical for concurrent access safety.
2025-12-01 13:43:52 +00:00
rcourtman
2d75350dfa
test: Add error path tests for renderWebhookURL and UpdateAllowedPrivateCIDRs
...
Add comprehensive error handling tests for two pure functions:
renderWebhookURL (8 new test cases):
- Empty/whitespace URL template validation
- Invalid template syntax (unclosed braces, undefined functions)
- Template producing empty URL
- Missing scheme or host in rendered URL
UpdateAllowedPrivateCIDRs (expanded from 8 to 29 cases):
- Invalid IP addresses (garbage, out of range, malformed)
- Invalid CIDR notation (prefix too large, negative, non-numeric)
- Malformed strings (double slash, invalid IP with valid prefix)
- Success cases for valid IPv4/IPv6 CIDRs and bare IPs
2025-12-01 12:58:15 +00:00
rcourtman
604e4dcd4a
test: Add unit tests for email_enhanced.go error handling
...
Add comprehensive tests for EnhancedEmailManager covering:
- Rate limiting (exceeds limit, resets after minute, concurrency, negative values)
- Provider username defaults (SendGrid, SparkPost, Resend, Postmark)
- TLS routing (TLS, StartTLS, plain connections)
- Retry logic (retries on failure, rate limit prevents retry)
- Connection error handling for sendTLS, sendStartTLS, sendPlain
This is the first test file for email_enhanced.go which previously had
0% coverage on sendTLS, sendStartTLS, and TestConnection functions.
2025-12-01 11:46:44 +00:00
rcourtman
01ab7053c0
Add unit tests for notification utility functions
...
Tests for annotateResolvedMetadata, resolveAppriseNotificationType,
normalizeQueueType, and resolvedTimeFromAlerts (44 test cases).
Coverage 38.0% → 39.0%.
2025-12-01 02:04:27 +00:00
rcourtman
18635fe960
Add unit tests for isRetryableWebhookError (internal/notifications)
...
47 test cases covering webhook retry logic classification:
- Network errors: timeout, connection refused/reset, DNS lookup, network unreachable
- HTTP 5xx server errors: all status codes 500-599 (retryable)
- HTTP 4xx client errors: all status codes 400-499 except 429 (not retryable)
- HTTP 429 rate limiting: special case (retryable)
- Case insensitivity verification
- Real-world error message patterns from Go net/http
- All status code boundary tests
Coverage 37.4% -> 38.0%.
2025-11-30 22:03:26 +00:00
rcourtman
0e25712d8e
Add unit tests for notification security utilities (notifications)
...
Test 7 security-related functions with 118 test cases:
- formatWebhookDuration: webhook payload duration formatting
- isNumeric: Telegram chat_id validation helper
- extractTelegramChatID: Telegram webhook URL parsing
- isPrivateIP: SSRF protection (private IP detection)
- isNumericIP: HTTPS IP address detection
- isEmptyInterface: custom field validation
- ensurePushoverCustomFieldAliases: Pushover legacy field aliasing
2025-11-30 08:05:04 +00:00
rcourtman
2857a87c91
Add unit tests for notification template functions (notifications)
...
Test GetEmailProviders and GetWebhookTemplates functions covering:
- Provider/template uniqueness, required fields, valid values
- Known provider settings (Gmail, SendGrid, custom)
- Known webhook services (Discord, Slack, Telegram, PagerDuty)
- Payload template validation for required alert fields
2025-11-30 07:48:53 +00:00
rcourtman
5be678f88d
Add unit tests for notification queue utility functions
...
Test coverage for calculateBackoff (exponential backoff calculation),
NotificationQueueStatus constants, and QueuedNotification struct fields.
15 test cases covering backoff timing, cap behavior, and struct defaults.
2025-11-30 03:19:23 +00:00
rcourtman
59971e0862
Add unit tests for email template utility functions
...
Test coverage for titleCase, formatDuration, pluralize, formatMetricValue,
and formatMetricThreshold functions. 71 test cases covering edge cases,
boundary conditions, and all metric type variants.
2025-11-30 01:03:05 +00:00
rcourtman
69051d5fe1
refactor: replace deprecated strings.Title with custom titleCase
...
Add simple titleCase functions that handle ASCII strings without
the Unicode punctuation issues of strings.Title.
2025-11-27 09:22:52 +00:00
rcourtman
611740087c
style: fix additional staticcheck warnings
...
- Lowercase error messages (ST1005)
- Use context.Background() instead of nil (SA1012)
- Fix rand.Intn(1) which always returns 0 (SA4030)
- Remove unnecessary nil check before len() (S1009)
2025-11-27 09:21:11 +00:00
rcourtman
ad998a1e2f
style: fix staticcheck style warnings
...
- Merge variable declaration with assignment (S1021)
- Use unconditional strings.TrimPrefix (S1017)
- Remove unnecessary nil checks around range (S1031)
- Remove unnecessary fmt.Sprintf (S1039)
- Use copy() instead of manual loop (S1001)
- Use time.Until instead of t.Sub(time.Now()) (S1024)
- Use buf.String() instead of string(buf.Bytes()) (S1030)
2025-11-27 09:19:33 +00:00
rcourtman
b370799988
chore: remove more dead code
...
Remove 330 lines of unreachable code:
- internal/monitoring/temperature_service.go: unused temperature service abstraction
- internal/monitoring/temperature.go: unused NewTemperatureCollector wrapper
- internal/mock/generator.go: unused GenerateAlerts function
- internal/mock/integration.go: unused ToggleMockMode wrapper
- internal/notifications/notifications.go: unused sendEmailWithContent,
generatePayloadFromTemplate, isPrivateRange172, groupAlerts
- internal/notifications/email_providers.go: unused GetProviderDefaults
2025-11-27 00:10:55 +00:00
rcourtman
01f7d81d38
style: fix gofmt formatting inconsistencies
...
Run gofmt -w to fix tab/space inconsistencies across 33 files.
2025-11-26 23:44:36 +00:00
rcourtman
255357d2fe
Add recovery notifications and grouping controls
2025-11-21 22:07:00 +00:00
rcourtman
11d7f4fd4e
Add Apprise test support for notifications
...
Related to #584
2025-11-20 17:54:20 +00:00
rcourtman
6a1a88217f
Add release dry run workflow and API update integration test
2025-11-12 21:02:52 +00:00