v0.37.2
This commit is contained in:
1 parent
f48843e934
commit
e2c8099d9c
64 files changed
+5354
-673
No files matched your search
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestProcAddressesWithoutNetlink(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
write := func(name, body string) {
|
||||
if err := os.WriteFile(filepath.Join(dir, name), []byte(body), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
write("route", "Iface\tDestination\tGateway \tFlags\tRefCnt\tUse\tMetric\tMask\t\tMTU\tWindow\tIRTT\n"+
|
||||
"eth0\t00000000\t0102570A\t0003\t0\t0\t0\t00000000\t0\t0\t0\n"+
|
||||
"eth0\t0002570A\t00000000\t0001\t0\t0\t0\t00FFFFFF\t0\t0\t0\n"+
|
||||
"eth1\t0010A8C0\t00000000\t0001\t0\t0\t0\t00FFFFFF\t0\t0\t0\n"+
|
||||
"docker0\t000011AC\t00000000\t0001\t0\t0\t0\t0000FFFF\t0\t0\t0\n")
|
||||
write("fib_trie", "Main:\n +-- 0.0.0.0/0 3 0 5\n |-- 10.87.2.6\n /32 host LOCAL\n |-- 192.168.16.4\n /32 host LOCAL\n |-- 172.17.0.1\n /32 host LOCAL\n |-- 127.0.0.1\n /32 host LOCAL\nLocal:\n |-- 10.87.2.6\n /32 host LOCAL\n")
|
||||
write("if_inet6", "20010db8000000000000000000000001 02 40 00 80 eth1\nfe800000000000000000000000000001 02 40 20 80 eth0\n00000000000000000000000000000001 01 80 10 80 lo\n")
|
||||
items := procAddresses(dir)
|
||||
host := procInterfaceAddresses(items, false, "interface")
|
||||
got := map[string]string{}
|
||||
for _, item := range host {
|
||||
got[item.IP] = item.Interface
|
||||
}
|
||||
if got["10.87.2.6"] != "eth0" || got["192.168.16.4"] != "eth1" || got["2001:db8::1"] != "eth1" {
|
||||
t.Fatalf("unexpected host addresses: %#v", host)
|
||||
}
|
||||
if _, ok := got["172.17.0.1"]; ok {
|
||||
t.Fatalf("bridge address listed as host interface: %#v", host)
|
||||
}
|
||||
bridges := procInterfaceAddresses(items, true, "bridge")
|
||||
if len(bridges) != 1 || bridges[0].IP != "172.17.0.1" || bridges[0].Interface != "docker0" {
|
||||
t.Fatalf("unexpected bridge addresses: %#v", bridges)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user