-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherror_classify_test.go
More file actions
131 lines (113 loc) · 3.63 KB
/
error_classify_test.go
File metadata and controls
131 lines (113 loc) · 3.63 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package zeroconf
import (
"errors"
"fmt"
"syscall"
"testing"
)
func TestIsInterfaceGone_Nil_ReturnsFalse(t *testing.T) {
if isInterfaceGone(nil) {
t.Error("expected false for nil error")
}
}
func TestIsInterfaceGone_ENXIO_ReturnsTrue(t *testing.T) {
err := syscall.ENXIO
if !isInterfaceGone(err) {
t.Errorf("expected true for ENXIO, got false")
}
}
func TestIsInterfaceGone_ENODEV_ReturnsTrue(t *testing.T) {
err := syscall.ENODEV
if !isInterfaceGone(err) {
t.Errorf("expected true for ENODEV, got false")
}
}
func TestIsInterfaceGone_EADDRNOTAVAIL_ReturnsTrue(t *testing.T) {
err := syscall.EADDRNOTAVAIL
if !isInterfaceGone(err) {
t.Errorf("expected true for EADDRNOTAVAIL, got false")
}
}
func TestIsInterfaceGone_EINVAL_ReturnsTrue(t *testing.T) {
err := syscall.EINVAL
if !isInterfaceGone(err) {
t.Errorf("expected true for EINVAL, got false")
}
}
func TestIsInterfaceGone_ENETDOWN_ReturnsTrue(t *testing.T) {
err := syscall.ENETDOWN
if !isInterfaceGone(err) {
t.Errorf("expected true for ENETDOWN, got false")
}
}
func TestIsInterfaceGone_ENETUNREACH_ReturnsTrue(t *testing.T) {
err := syscall.ENETUNREACH
if !isInterfaceGone(err) {
t.Errorf("expected true for ENETUNREACH, got false")
}
}
func TestIsInterfaceGone_WrappedError_ReturnsTrue(t *testing.T) {
// errors.Is() should unwrap fmt.Errorf("%w") chains
wrapped := fmt.Errorf("send failed: %w", syscall.ENXIO)
if !isInterfaceGone(wrapped) {
t.Errorf("expected true for wrapped ENXIO, got false")
}
}
func TestIsInterfaceGone_DoubleWrappedError_ReturnsTrue(t *testing.T) {
inner := fmt.Errorf("inner: %w", syscall.ENETDOWN)
outer := fmt.Errorf("outer: %w", inner)
if !isInterfaceGone(outer) {
t.Errorf("expected true for double-wrapped ENETDOWN, got false")
}
}
func TestIsInterfaceGone_TransientError_ReturnsFalse(t *testing.T) {
// EAGAIN is a transient error - should not remove interface
err := syscall.EAGAIN
if isInterfaceGone(err) {
t.Errorf("expected false for EAGAIN (transient), got true")
}
}
func TestIsInterfaceGone_ETIMEDOUT_ReturnsFalse(t *testing.T) {
// Timeout is transient - interface might still be fine
err := syscall.ETIMEDOUT
if isInterfaceGone(err) {
t.Errorf("expected false for ETIMEDOUT (transient), got true")
}
}
func TestIsInterfaceGone_GenericError_ReturnsFalse(t *testing.T) {
err := errors.New("some random error")
if isInterfaceGone(err) {
t.Errorf("expected false for generic error, got true")
}
}
func TestIsInterfaceGone_FallbackMessageParsing_NoSuchDevice(t *testing.T) {
// Fallback for unknown error codes with recognizable message
err := errors.New("operation failed: no such device")
if !isInterfaceGone(err) {
t.Errorf("expected true for 'no such device' message, got false")
}
}
func TestIsInterfaceGone_FallbackMessageParsing_NetworkDown(t *testing.T) {
err := errors.New("send error: network is down")
if !isInterfaceGone(err) {
t.Errorf("expected true for 'network is down' message, got false")
}
}
func TestIsInterfaceGone_FallbackMessageParsing_NetworkUnreachable(t *testing.T) {
err := errors.New("cannot route: network is unreachable")
if !isInterfaceGone(err) {
t.Errorf("expected true for 'network is unreachable' message, got false")
}
}
func TestIsInterfaceGone_FallbackMessageParsing_NoSuchInterface(t *testing.T) {
err := errors.New("interface eth0: no such interface")
if !isInterfaceGone(err) {
t.Errorf("expected true for 'no such interface' message, got false")
}
}
func TestIsInterfaceGone_FallbackMessageParsing_CaseInsensitive(t *testing.T) {
err := errors.New("NETWORK IS DOWN")
if !isInterfaceGone(err) {
t.Errorf("expected true for uppercase 'NETWORK IS DOWN', got false")
}
}