-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: add support for errors.Is() on QuorumCallError
This refactors the QuorumCallError to support the errors.Is() func. This is a breaking change since it unexports the Reason field; users of the QuorumCallError must update their code to use the errors.Is() function. This also adds the gorums.Incomplete sentinal error that can be used to check for incomplete quorum calls.
- Loading branch information
Showing
6 changed files
with
84 additions
and
12 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
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,60 @@ | ||
package gorums | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
) | ||
|
||
func TestQuorumCallErrorIs(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
err error | ||
target error | ||
want bool | ||
}{ | ||
{ | ||
name: "SameCauseError", | ||
err: QuorumCallError{cause: Incomplete}, | ||
target: Incomplete, | ||
want: true, | ||
}, | ||
{ | ||
name: "SameCauseQCError", | ||
err: QuorumCallError{cause: Incomplete}, | ||
target: QuorumCallError{cause: Incomplete}, | ||
want: true, | ||
}, | ||
{ | ||
name: "DifferentError", | ||
err: QuorumCallError{cause: Incomplete}, | ||
target: errors.New("incomplete call"), | ||
want: false, | ||
}, | ||
{ | ||
name: "DifferentQCError", | ||
err: QuorumCallError{cause: Incomplete}, | ||
target: QuorumCallError{cause: errors.New("incomplete call")}, | ||
want: false, | ||
}, | ||
{ | ||
name: "ContextCanceled", | ||
err: QuorumCallError{cause: context.Canceled}, | ||
target: context.Canceled, | ||
want: true, | ||
}, | ||
{ | ||
name: "ContextCanceledQC", | ||
err: QuorumCallError{cause: context.Canceled}, | ||
target: QuorumCallError{cause: context.Canceled}, | ||
want: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := errors.Is(tt.err, tt.target); got != tt.want { | ||
t.Errorf("QuorumCallError.Is(%v, %v) = %v, want %v", tt.err, tt.target, got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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