-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api): failover error bugs (#858)
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package api | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestErrorFailoverErrorsIs(t *testing.T) { | ||
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") | ||
} | ||
|
||
if !errors.Is(failoverErr, &ErrorFailover{}) { | ||
t.Error("should match ErrorFailover type") | ||
} | ||
|
||
if !errors.Is(wrappedFailoverErr, &ErrorFailover{}) { | ||
t.Error("should match ErrorFailover type even when wrapped") | ||
} | ||
|
||
} | ||
|
||
func TestErrorFailoverZeroValue(t *testing.T) { | ||
var failoverErr ErrorFailover | ||
if failoverErr.Error() != "Failover" { | ||
t.Error("should return 'Failover' for zero value") | ||
} | ||
} |