package main import ( "os" "path/filepath" "testing" ) func TestReadNetworkSnapshot(t *testing.T) { path := filepath.Join(t.TempDir(), "netdev") content := `Inter-| Receive | Transmit face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed lo: 100 1 0 0 0 0 0 0 100 1 0 0 0 0 0 0 eth0: 1200 2 0 0 0 0 0 0 3400 3 0 0 0 0 0 0 vmbr0: 5600 4 0 0 0 0 0 0 7800 5 0 0 0 0 0 0 ` if err := os.WriteFile(path, []byte(content), 0o600); err != nil { t.Fatal(err) } snapshot, interfaces, details, err := readNetworkSnapshot(path) if err != nil { t.Fatal(err) } if snapshot.received != 6800 || snapshot.sent != 11200 { t.Fatalf("неожиданные сетевые счётчики: %+v", snapshot) } if len(interfaces) != 2 { t.Fatalf("неожиданный список интерфейсов: %v", interfaces) } if len(details) != 2 { t.Fatalf("unexpected interface details: %+v", details) } } func TestInterfaceVMID(t *testing.T) { for name, want := range map[string]int{"tap100i0": 100, "veth108i0": 108, "fwbr113i0": 113, "vmbr0": 0, "enp6s0": 0} { if got := interfaceVMID(name); got != want { t.Fatalf("%s: got %d want %d", name, got, want) } } }