diff --git a/api/errors_test.go b/api/errors_test.go index 8409f5215f..f630bdc39e 100644 --- a/api/errors_test.go +++ b/api/errors_test.go @@ -7,17 +7,32 @@ import ( ) func TestErrorFailoverErrorsIs(t *testing.T) { - baseErr := fmt.Errorf("some error") + baseErr := fmt.Errorf("base error") failoverErr := NewErrorFailover(baseErr) + otherFailoverErr := NewErrorFailover(fmt.Errorf("some other error")) + wrappedFailoverErr := fmt.Errorf("wrapped: %w", failoverErr) + + if !errors.Is(failoverErr, failoverErr) { + t.Error("should match itself") + } + + if !errors.Is(failoverErr, baseErr) { + t.Error("should match base error") + } + + if errors.Is(failoverErr, fmt.Errorf("some other error")) { + t.Error("should not match other errors") + } + + if !errors.Is(failoverErr, otherFailoverErr) { + t.Error("should match other failover error") + } - // error comparison only checks the type of the error if !errors.Is(failoverErr, &ErrorFailover{}) { t.Error("should match ErrorFailover type") } - // can also compare if failover error is wrapped - wrapped := fmt.Errorf("wrapped: %w", failoverErr) - if !errors.Is(wrapped, &ErrorFailover{}) { + if !errors.Is(wrappedFailoverErr, &ErrorFailover{}) { t.Error("should match ErrorFailover type even when wrapped") }