Show this Postfix's retry policy on Mail queue and delivery history.
test / test (push) Waiting to run

Numbers come from a one-shot postconf -h at panel start so a manual override is visible after restart, without inventing an attempt count.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-17 22:12:03 +03:00
parent 46191172d6
commit 705239568b
17 changed files with 669 additions and 30 deletions
+64
View File
@@ -0,0 +1,64 @@
package postfix
import (
"testing"
"time"
)
func TestParseDuration(t *testing.T) {
cases := []struct {
in string
want time.Duration
}{
{"5d", 5 * 24 * time.Hour},
{"300s", 300 * time.Second},
{"4000s", 4000 * time.Second},
{"1h", time.Hour},
{"0", 0},
{"0s", 0},
{"300", 300 * time.Second},
{" 300s ", 300 * time.Second},
{"1h7m", time.Hour + 7*time.Minute},
{"1w", 7 * 24 * time.Hour},
{"2m", 2 * time.Minute},
}
for _, tc := range cases {
got, err := ParseDuration(tc.in)
if err != nil {
t.Errorf("ParseDuration(%q): %v", tc.in, err)
continue
}
if got != tc.want {
t.Errorf("ParseDuration(%q) = %v, want %v", tc.in, got, tc.want)
}
}
}
func TestParseDurationRejectsInvalid(t *testing.T) {
for _, in := range []string{"", "foo", "5x", "-300s", "s", "1h 5x"} {
if _, err := ParseDuration(in); err == nil {
t.Errorf("ParseDuration(%q) = nil, want error", in)
}
}
}
func TestFormatDuration(t *testing.T) {
cases := []struct {
in time.Duration
want string
}{
{5 * 24 * time.Hour, "5 days"},
{300 * time.Second, "5 minutes"},
{4000 * time.Second, "about 1 hour 7 minutes"},
{time.Hour, "1 hour"},
{0, "0 seconds"},
{time.Second, "1 second"},
{2 * time.Minute, "2 minutes"},
{24 * time.Hour, "1 day"},
}
for _, tc := range cases {
if got := FormatDuration(tc.in); got != tc.want {
t.Errorf("FormatDuration(%v) = %q, want %q", tc.in, got, tc.want)
}
}
}