Skip to content

Commit 7656182

Browse files
committed
add tests
1 parent 01c4d61 commit 7656182

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

internal/conn/error_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,41 @@ func TestNodeErrorUnwrap(t *testing.T) {
2222
unwrapped := errors.Unwrap(nodeErr)
2323
require.Equal(t, testErr, unwrapped)
2424
}
25+
26+
func TestNodeErrorIs(t *testing.T) {
27+
testErr := errors.New("test")
28+
testErr2 := errors.New("test2")
29+
nodeErr := newNodeError(1, "localhost:1234", testErr)
30+
31+
require.True(t, errors.Is(nodeErr, testErr))
32+
require.False(t, errors.Is(nodeErr, testErr2))
33+
}
34+
35+
type testErrorType1 struct {
36+
msg string
37+
}
38+
39+
func (t testErrorType1) Error() string {
40+
return "1 - " + t.msg
41+
}
42+
43+
type testErrorType2 struct {
44+
msg string
45+
}
46+
47+
func (t testErrorType2) Error() string {
48+
return "2 - " + t.msg
49+
}
50+
51+
func TestNodeErrorAs(t *testing.T) {
52+
testErr := testErrorType1{msg: "test"}
53+
nodeErr := newNodeError(1, "localhost:1234", testErr)
54+
55+
target := testErrorType1{}
56+
require.True(t, errors.As(nodeErr, &target))
57+
require.ErrorAs(t, nodeErr, &target)
58+
require.Equal(t, testErr, target)
59+
60+
target2 := testErrorType2{}
61+
require.False(t, errors.As(nodeErr, &target2))
62+
}

0 commit comments

Comments
 (0)