ultisuite-backend/internal/mail/webhooks/executor_retry_test.go
R3D347HR4Y 1b9a3394e2 Implement rule simulation and webhook enhancements
- Added a new endpoint for simulating rules based on sample messages, allowing users to test rule conditions and actions.
- Enhanced webhook management with versioning, preview capabilities, and improved validation for webhook requests.
- Updated service interfaces to support new functionalities, including max retries for webhooks and signing secrets.
- Implemented observability metrics for webhook retries and dead-letter tracking, improving error handling and monitoring.
- Enhanced unit tests to cover new simulation and webhook features, ensuring robust functionality and validation.
2026-05-22 17:53:51 +02:00

47 lines
1.1 KiB
Go

package webhooks
import (
"strings"
"testing"
"time"
)
func TestWebhookRetryDelay(t *testing.T) {
tests := []struct {
attempt int
want time.Duration
}{
{attempt: 1, want: 500 * time.Millisecond},
{attempt: 2, want: time.Second},
{attempt: 3, want: 2 * time.Second},
{attempt: 6, want: 8 * time.Second},
{attempt: 9, want: 8 * time.Second},
}
for _, tt := range tests {
if got := webhookRetryDelay(tt.attempt); got != tt.want {
t.Fatalf("webhookRetryDelay(%d) = %v, want %v", tt.attempt, got, tt.want)
}
}
}
func TestSignPayload(t *testing.T) {
got := signPayload("secret", "1716372000", `{"ok":true}`)
if !strings.HasPrefix(got, "sha256=") {
t.Fatalf("signature prefix missing: %q", got)
}
if len(got) != len("sha256=")+64 {
t.Fatalf("signature length = %d, want %d", len(got), len("sha256=")+64)
}
}
func TestTruncateForLog(t *testing.T) {
preview, truncated := truncateForLog("abcdef", 4)
if !truncated {
t.Fatal("truncated = false, want true")
}
if preview != "abcd" {
t.Fatalf("preview = %q, want %q", preview, "abcd")
}
}