| 51 | } |
| 52 | |
| 53 | func TestErrorNetError(t *testing.T) { |
| 54 | cases := []struct { |
| 55 | err error |
| 56 | str string |
| 57 | timeout, temporary bool |
| 58 | }{ |
| 59 | {&FatalError{Err: errExample}, "dtls fatal: an example error", false, false}, |
| 60 | {&TemporaryError{Err: errExample}, "dtls temporary: an example error", false, true}, |
| 61 | {&InternalError{Err: errExample}, "dtls internal: an example error", false, false}, |
| 62 | {&TimeoutError{Err: errExample}, "dtls timeout: an example error", true, true}, |
| 63 | {&HandshakeError{Err: errExample}, "handshake error: an example error", false, false}, |
| 64 | {&HandshakeError{Err: &TimeoutError{Err: errExample}}, "handshake error: dtls timeout: an example error", true, true}, |
| 65 | } |
| 66 | for _, testCase := range cases { |
| 67 | t.Run(fmt.Sprintf("%T", testCase.err), func(t *testing.T) { |
| 68 | var ne net.Error |
| 69 | assert.ErrorAs(t, testCase.err, &ne) |
| 70 | assert.Equal(t, testCase.timeout, ne.Timeout()) |
| 71 | assert.Equal(t, testCase.temporary, ne.Temporary()) //nolint:staticcheck |
| 72 | assert.Equal(t, testCase.str, ne.Error()) |
| 73 | }) |
| 74 | } |
| 75 | } |