35 lines
983 B
Go
35 lines
983 B
Go
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)
|
|
}
|
|
}
|