Skip to content
File

Blob: spec/chord/errors_test.go

go57 lines
1package chord
2 
3import (
4 "testing"
5 
6 "github.com/stretchr/testify/require"
7 "github.com/twitchtv/twirp"
8)
9 
10type errorWrapper struct {
11 err error
12}
13 
14var _ error = (*errorWrapper)(nil)
15 
16func (e *errorWrapper) Error() string {
17 return e.err.Error()
18}
19 
20func TestErrorMapper(t *testing.T) {
21 as := require.New(t)
22 
23 errors := []error{
24 ErrNodeGone,
25 ErrNodeNotStarted,
26 ErrNodeNoSuccessor,
27 ErrNodeNil,
28 
29 ErrDuplicateJoinerID,
30 ErrJoinInvalidSuccessor,
31 ErrJoinInvalidState,
32 ErrJoinTransferFailure,
33 ErrLeaveInvalidState,
34 ErrLeaveTransferFailure,
35 
36 ErrKVStaleOwnership,
37 ErrKVPendingTransfer,
38 
39 ErrKVSimpleConflict,
40 ErrKVPrefixConflict,
41 ErrKVLeaseConflict,
42 
43 ErrKVLeaseExpired,
44 ErrKVLeaseInvalidTTL,
45 }
46 
47 call := func(_ any, err error) (any, error) {
48 // type squashing
49 return nil, ErrorMapper(twirp.Internal.Error(err.Error()))
50 }
51 
52 for _, real := range errors {
53 _, mapped := call(nil, real)
54 as.ErrorIs(mapped, real)
55 }
56}