Skip to content

Commit

Permalink
test(api): add more tests for FailoverError
Browse files Browse the repository at this point in the history
  • Loading branch information
samlaf committed Nov 1, 2024
1 parent 48ccf9e commit 7d41cf7
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions api/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit 7d41cf7

Please sign in to comment.