use nlink::netlink::link::DummyLink;
use tokio_stream::StreamExt;
use crate::common::TestNamespace;
#[tokio::test]
async fn stream_links_yields_all_populated_links() -> nlink::Result<()> {
require_root!();
nlink::require_modules!("dummy");
let ns = TestNamespace::new("stream-links")?;
let conn = ns.connection()?;
for i in 0..5 {
conn.add_link(DummyLink::new(format!("d{i}"))).await?;
}
let mut count = 0usize;
let mut stream = conn.stream_links().await?;
while let Some(item) = stream.next().await {
item?;
count += 1;
}
assert!(
count >= 6,
"stream_links should observe loopback + 5 dummies (≥ 6); got {count}"
);
Ok(())
}
#[tokio::test]
async fn stream_links_matches_eager_dump_count() -> nlink::Result<()> {
require_root!();
nlink::require_modules!("dummy");
let ns = TestNamespace::new("stream-vs-eager")?;
let conn = ns.connection()?;
for i in 0..3 {
conn.add_link(DummyLink::new(format!("d{i}"))).await?;
}
let eager = conn.get_links().await?;
let mut streamed = 0usize;
let mut stream = conn.stream_links().await?;
while let Some(item) = stream.next().await {
item?;
streamed += 1;
}
assert_eq!(
streamed,
eager.len(),
"streaming dump must parse the same frame count as the eager dump"
);
Ok(())
}