@@ -60,3 +60,50 @@ func TestInterfacesDarwin(t *testing.T) {
6060 }
6161 }
6262}
63+
64+ func TestInterfacesLinux (t * testing.T ) {
65+ conn , err := mock .New (0 , "./testdata/linux.toml" , & inventory.Asset {})
66+ require .NoError (t , err )
67+ platform , ok := detector .DetectOS (conn )
68+ require .True (t , ok )
69+
70+ interfaces , err := subject .Interfaces (conn , platform )
71+ require .NoError (t , err )
72+ assert .Len (t , interfaces , 2 )
73+
74+ index := subject .FindInterface (interfaces , subject.Interface {Name : "enX0" })
75+ if assert .NotEqual (t , - 1 , index ) {
76+ enX0 := interfaces [index ]
77+ assert .Equal (t , "enX0" , enX0 .Name )
78+ assert .Equal (t , "0a:ff:de:6b:e3:19" , enX0 .MACAddress )
79+ assert .Equal (t , "" , enX0 .Vendor )
80+ assert .Equal (t , 9001 , enX0 .MTU )
81+ if assert .NotNil (t , enX0 .Active ) {
82+ assert .True (t , * enX0 .Active )
83+ }
84+ if assert .NotNil (t , enX0 .Virtual ) {
85+ assert .False (t , * enX0 .Virtual )
86+ }
87+ assert .Equal (t , []string {"BROADCAST" , "MULTICAST" , "UP" , "LOWER_UP" }, enX0 .Flags )
88+ if assert .NotEmpty (t , enX0 .IPAddresses ) {
89+ i4 := enX0 .FindIP (net .ParseIP ("172.31.24.71" ))
90+ if assert .NotEqual (t , - 1 , i4 ) {
91+ ipv4 := enX0 .IPAddresses [i4 ]
92+ assert .Equal (t , "172.31.24.71" , ipv4 .IP .String ())
93+ assert .Equal (t , "172.31.24.71/20" , ipv4 .CIDR )
94+ assert .Equal (t , "172.31.16.0/20" , ipv4 .Subnet )
95+ assert .Equal (t , "172.31.31.255" , ipv4 .Broadcast )
96+ assert .Equal (t , "172.31.16.1" , ipv4 .Gateway )
97+ }
98+ i6 := enX0 .FindIP (net .ParseIP ("fe80::8ff:deff:fe6b:e319" ))
99+ if assert .NotEqual (t , - 1 , i6 ) {
100+ ipv6 := enX0 .IPAddresses [i6 ]
101+ assert .Equal (t , "fe80::8ff:deff:fe6b:e319" , ipv6 .IP .String ())
102+ assert .Equal (t , "fe80::8ff:deff:fe6b:e319/64" , ipv6 .CIDR )
103+ assert .Equal (t , "fe80::/64" , ipv6 .Subnet )
104+ assert .Equal (t , "" , ipv6 .Broadcast )
105+ assert .Equal (t , "" , ipv6 .Gateway )
106+ }
107+ }
108+ }
109+ }
0 commit comments