package merrors import ( "errors" "testing" "time" ) func TestWithThrottlePreservesClassificationAndDetails(t *testing.T) { base := Define("verificationLimited") err := Wrap( WithThrottle(base, " destination ", 45*time.Second, "request is temporarily limited"), "verification failed", ) if !errors.Is(err, base) { t.Fatalf("throttle error did not preserve classification: %v", err) } details, ok := ThrottleDetailsFrom(err) if !ok { t.Fatal("throttle details were not available through wrapping") } if details.ScopeKind != "destination" || details.RetryAfter != 45*time.Second { t.Fatalf("unexpected throttle details: %+v", details) } if got, want := err.Error(), "verificationLimited: request is temporarily limited: verification failed"; got != want { t.Fatalf("unexpected throttle error text: got=%q want=%q", got, want) } } func TestThrottleDetailsFromRejectsUnannotatedError(t *testing.T) { if details, ok := ThrottleDetailsFrom(ServiceUnavailable("dependency unavailable")); ok { t.Fatalf("unexpected throttle details: %+v", details) } }