Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

test: Add sendHTMLEmailWithError tests

rcourtman251b252062e9
diff --git a/internal/notifications/notifications_test.go b/internal/notifications/notifications_test.go
index 057b037b7a..c2506c8cbb 100644
--- a/internal/notifications/notifications_test.go
+++ b/internal/notifications/notifications_test.go
@@ -2592,3 +2592,77 @@ func TestSendGroupedApprise_EmptyPayload(t *testing.T) {
t.Errorf("expected 'failed to build apprise payload' error, got: %v", err)
}
}
+
+func TestSendHTMLEmailWithError_EmptyToUsesFrom(t *testing.T) {
+ nm := &NotificationManager{}
+ config := EmailConfig{
+ To: []string{}, // Empty To
+ SMTPHost: "invalid.localhost.test",
+ SMTPPort: 25,
+ }
+
+ // Will fail at SMTP connection but exercises the "use From as recipient" path
+ err := nm.sendHTMLEmailWithError("Test Subject", "<p>test</p>", "test", config)
+ if err == nil {
+ t.Error("expected error for invalid SMTP host")
+ }
+ // The key test is that it tried to send - error message should mention SMTP failure
+ if err != nil && !strings.Contains(err.Error(), "failed to send email") {
+ t.Errorf("expected 'failed to send email' error, got: %v", err)
+ }
+}
+
+func TestSendHTMLEmailWithError_NilEmailManager(t *testing.T) {
+ nm := &NotificationManager{
+ emailManager: nil, // Explicitly nil
+ }
+ config := EmailConfig{
+ To: []string{"[email protected]"},
+ SMTPHost: "invalid.localhost.test",
+ SMTPPort: 587,
+ Username: "user",
+ Password: "pass",
+ }
+
+ // Will fail but exercises the nil emailManager path (creates a new one)
+ err := nm.sendHTMLEmailWithError("Test Subject", "<p>test</p>", "test", config)
+ if err == nil {
+ t.Error("expected error for invalid SMTP host")
+ }
+}
+
+func TestSendHTMLEmailWithError_ExistingEmailManager(t *testing.T) {
+ // Create an email manager first
+ existingManager := NewEnhancedEmailManager(EmailProviderConfig{
+ EmailConfig: EmailConfig{
+ To: []string{"[email protected]"},
+ SMTPHost: "old.localhost.test",
+ SMTPPort: 25,
+ },
+ })
+
+ nm := &NotificationManager{
+ emailManager: existingManager,
+ }
+
+ config := EmailConfig{
+ To: []string{"[email protected]"},
+ SMTPHost: "invalid.localhost.test",
+ SMTPPort: 587,
+ }
+
+ // Will fail but exercises the "update existing manager config" path
+ err := nm.sendHTMLEmailWithError("Test Subject", "<p>test</p>", "test", config)
+ if err == nil {
+ t.Error("expected error for invalid SMTP host")
+ }
+
+ // Verify the manager's config was updated
+ if existingManager.config.EmailConfig.From != "[email protected]" {
+ t.Errorf("expected From to be updated to '[email protected]', got %q", existingManager.config.EmailConfig.From)
+ }
+}