|
|
|
@ -5,6 +5,7 @@
|
|
|
|
|
package portlist
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -41,6 +42,10 @@ udp6 0 0 :::5354 :::*
|
|
|
|
|
// macOS
|
|
|
|
|
tcp4 0 0 *.23 *.* LISTEN
|
|
|
|
|
tcp6 0 0 *.24 *.* LISTEN
|
|
|
|
|
tcp4 0 0 *.8185 *.* LISTEN
|
|
|
|
|
tcp4 0 0 127.0.0.1.8186 *.* LISTEN
|
|
|
|
|
tcp6 0 0 ::1.8187 *.* LISTEN
|
|
|
|
|
|
|
|
|
|
udp6 0 0 *.5453 *.*
|
|
|
|
|
udp4 0 0 *.5553 *.*
|
|
|
|
|
|
|
|
|
@ -73,14 +78,21 @@ func TestParsePortsNetstat(t *testing.T) {
|
|
|
|
|
Port{"udp", 5354, "", ""},
|
|
|
|
|
Port{"udp", 5453, "", ""},
|
|
|
|
|
Port{"udp", 5553, "", ""},
|
|
|
|
|
Port{"tcp", 8185, "", ""}, // but not 8186 or 8187 on localhost
|
|
|
|
|
Port{"udp", 9353, "iTunes", ""},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pl := parsePortsNetstat(netstatOutput)
|
|
|
|
|
jgot, _ := json.MarshalIndent(pl, "", "\t")
|
|
|
|
|
jwant, _ := json.MarshalIndent(want, "", "\t")
|
|
|
|
|
if len(pl) != len(want) {
|
|
|
|
|
t.Fatalf("Got:\n%s\n\nWant:\n%s\n", jgot, jwant)
|
|
|
|
|
}
|
|
|
|
|
for i := range pl {
|
|
|
|
|
if pl[i] != want[i] {
|
|
|
|
|
t.Errorf("row#%d\n got: %#v\n\nwant: %#v\n",
|
|
|
|
|
i, pl[i], want[i])
|
|
|
|
|
t.Fatalf("Got:\n%s\n\nWant:\n%s\n", jgot, jwant)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|