-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy patherrors_test.go
More file actions
75 lines (69 loc) · 1.9 KB
/
errors_test.go
File metadata and controls
75 lines (69 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package dtls
import (
"errors"
"fmt"
"net"
"testing"
"github.com/stretchr/testify/assert"
)
var errExample = errors.New("an example error")
func TestErrorUnwrap(t *testing.T) {
cases := []struct {
err error
errUnwrapped []error
}{
{
&FatalError{Err: errExample},
[]error{errExample},
},
{
&TemporaryError{Err: errExample},
[]error{errExample},
},
{
&InternalError{Err: errExample},
[]error{errExample},
},
{
&TimeoutError{Err: errExample},
[]error{errExample},
},
{
&HandshakeError{Err: errExample},
[]error{errExample},
},
}
for _, c := range cases {
t.Run(fmt.Sprintf("%T", c.err), func(t *testing.T) {
err := c.err
for _, unwrapped := range c.errUnwrapped {
assert.ErrorIs(t, errors.Unwrap(err), unwrapped)
}
})
}
}
func TestErrorNetError(t *testing.T) {
cases := []struct {
err error
str string
timeout, temporary bool
}{
{&FatalError{Err: errExample}, "dtls fatal: an example error", false, false},
{&TemporaryError{Err: errExample}, "dtls temporary: an example error", false, true},
{&InternalError{Err: errExample}, "dtls internal: an example error", false, false},
{&TimeoutError{Err: errExample}, "dtls timeout: an example error", true, true},
{&HandshakeError{Err: errExample}, "handshake error: an example error", false, false},
{&HandshakeError{Err: &TimeoutError{Err: errExample}}, "handshake error: dtls timeout: an example error", true, true},
}
for _, testCase := range cases {
t.Run(fmt.Sprintf("%T", testCase.err), func(t *testing.T) {
var ne net.Error
assert.ErrorAs(t, testCase.err, &ne)
assert.Equal(t, testCase.timeout, ne.Timeout())
assert.Equal(t, testCase.temporary, ne.Temporary()) //nolint:staticcheck
assert.Equal(t, testCase.str, ne.Error())
})
}
}