//go:build linux package cluster import "testing" // TestSampleNetLoadBasic: the sampler must stay in [0,100], must return 0 on // the first (seeding) call, and must be stable across repeated calls. On a // CI/dev box without a speed-known physical NIC it may legitimately return 0 // every time — that's fine; we only assert the invariants, not a specific // value. func TestSampleNetLoadBasic(t *testing.T) { first := SampleNetLoad() if first < 0 || first > 100 { t.Fatalf("first sample out of range: %v", first) } for i := 0; i < 3; i++ { v := SampleNetLoad() if v < 0 || v > 100 { t.Fatalf("sample %d out of range: %v", i, v) } } } // TestIsPhysicalUplink: virtual/container interfaces must never count as // uplinks — a busy docker bridge would otherwise fake host saturation. func TestIsPhysicalUplink(t *testing.T) { cases := []struct { name string typ int want bool }{ {"lo", 772, false}, {"ens18", 1, true}, // ARPHRD_ETHER physical {"eth0", 1, true}, // ARPHRD_ETHER physical {"docker0", 1, false}, {"br-abc123", 1, false}, {"veth9f2c1a", 1, false}, {"wg0", 1, false}, {"tun0", 65534, false}, // ARPHRD_NONE software iface {"tap7", 1, false}, {"bond0", 1, true}, // real aggregated uplink counts } for _, c := range cases { if got := isPhysicalUplink(c.name, c.typ); got != c.want { t.Errorf("isPhysicalUplink(%q,%d)=%v want %v", c.name, c.typ, got, c.want) } } }