38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
package merrors
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestDocumentsReportOwnedReasonRoundTrip(t *testing.T) {
|
|
err := DocumentsReportOwned("report has an active payout")
|
|
if !errors.Is(err, ErrDataConflict) || !errors.Is(err, ErrDocumentsReportOwned) {
|
|
t.Fatalf("DocumentsReportOwned() classification = %v", err)
|
|
}
|
|
reason, ok := Reason(err)
|
|
if !ok || reason != ReasonDocumentsReportOwned {
|
|
t.Fatalf("Reason() = %q, %t", reason, ok)
|
|
}
|
|
restored, ok := FromReason(reason, "report has an active payout")
|
|
if !ok || !errors.Is(restored, ErrDataConflict) || !errors.Is(restored, ErrDocumentsReportOwned) {
|
|
t.Fatalf("FromReason() = %v, %t", restored, ok)
|
|
}
|
|
}
|
|
|
|
func TestDocumentsQuotationExpiredReasonRoundTrip(t *testing.T) {
|
|
err := DocumentsQuotationExpired("quotation expired")
|
|
if !errors.Is(err, ErrFailedPrecondition) || !errors.Is(err, ErrDocumentsQuotationExpired) {
|
|
t.Fatalf("DocumentsQuotationExpired() classification = %v", err)
|
|
}
|
|
reason, ok := Reason(err)
|
|
if !ok || reason != ReasonDocumentsQuotationExpired {
|
|
t.Fatalf("Reason() = %q, %t", reason, ok)
|
|
}
|
|
restored, ok := FromReason(reason, "quotation expired")
|
|
if !ok || !errors.Is(restored, ErrFailedPrecondition) ||
|
|
!errors.Is(restored, ErrDocumentsQuotationExpired) {
|
|
t.Fatalf("FromReason() = %v, %t", restored, ok)
|
|
}
|
|
}
|