This repository was archived by the owner on Jul 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatcher_linux_internal_test.go
More file actions
72 lines (66 loc) · 1.54 KB
/
watcher_linux_internal_test.go
File metadata and controls
72 lines (66 loc) · 1.54 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
//+build linux
package netstate
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/jsimonetti/rtnetlink"
)
func Test_process(t *testing.T) {
tests := []struct {
name string
msgs []rtnetlink.Message
want changeSet
}{
{
name: "link",
msgs: []rtnetlink.Message{
newLink(rtnetlink.OperStateUnknown),
newLink(rtnetlink.OperStateNotPresent),
newLink(rtnetlink.OperStateDown),
newLink(rtnetlink.OperStateLowerLayerDown),
newLink(rtnetlink.OperStateTesting),
newLink(rtnetlink.OperStateDormant),
newLink(rtnetlink.OperStateUp),
// Ensure another interface's data shows up.
&rtnetlink.LinkMessage{
Attributes: &rtnetlink.LinkAttributes{
Name: "test1",
OperationalState: rtnetlink.OperStateDown,
},
},
// Messages which have no effect on the output.
newLink(0xff),
&rtnetlink.LinkMessage{Attributes: nil},
},
want: map[string][]Change{
"test0": []Change{
LinkUnknown,
LinkNotPresent,
LinkDown,
LinkLowerLayerDown,
LinkTesting,
LinkDormant,
LinkUp,
},
"test1": []Change{
LinkDown,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if diff := cmp.Diff(tt.want, process(tt.msgs)); diff != "" {
t.Fatalf("unexpected change set (-want +got):\n%s", diff)
}
})
}
}
func newLink(op rtnetlink.OperationalState) rtnetlink.Message {
return &rtnetlink.LinkMessage{
Attributes: &rtnetlink.LinkAttributes{
Name: "test0",
OperationalState: op,
},
}
}