- socktop connector allows you to communicate with socktop agent directly from you code without needing to implement the agent API directly. - will also be used for non tui implementation of "socktop collector" in the future. - moved to rust 2024 to take advantage of some new features that helped with refactor. - fixed everything that exploded with update. - added rust docs for lib.
52 lines
1.7 KiB
Rust
52 lines
1.7 KiB
Rust
use socktop_connector::{
|
|
AgentRequest, AgentResponse, connect_to_socktop_agent, connect_to_socktop_agent_with_tls,
|
|
};
|
|
|
|
// Integration probe: only runs when SOCKTOP_WS is set to an agent WebSocket URL.
|
|
// Example: SOCKTOP_WS=ws://127.0.0.1:3000/ws cargo test -p socktop_connector --test integration_test -- --nocapture
|
|
#[tokio::test]
|
|
async fn probe_ws_endpoints() {
|
|
// Gate the test to avoid CI failures when no agent is running.
|
|
let url = match std::env::var("SOCKTOP_WS") {
|
|
Ok(v) if !v.is_empty() => v,
|
|
_ => {
|
|
eprintln!(
|
|
"skipping ws_probe: set SOCKTOP_WS=ws://host:port/ws to run this integration test"
|
|
);
|
|
return;
|
|
}
|
|
};
|
|
|
|
// Optional pinned CA for WSS/self-signed setups
|
|
let tls_ca = std::env::var("SOCKTOP_TLS_CA").ok();
|
|
|
|
let mut connector = if let Some(ca_path) = tls_ca {
|
|
connect_to_socktop_agent_with_tls(&url, ca_path, true)
|
|
.await
|
|
.expect("connect ws with TLS")
|
|
} else {
|
|
connect_to_socktop_agent(&url).await.expect("connect ws")
|
|
};
|
|
|
|
// Should get fast metrics quickly
|
|
let response = connector.request(AgentRequest::Metrics).await;
|
|
assert!(response.is_ok(), "expected Metrics payload within timeout");
|
|
if let Ok(AgentResponse::Metrics(_)) = response {
|
|
// Success
|
|
} else {
|
|
panic!("expected Metrics response");
|
|
}
|
|
|
|
// Processes may be gzipped and a bit slower, but should arrive
|
|
let response = connector.request(AgentRequest::Processes).await;
|
|
assert!(
|
|
response.is_ok(),
|
|
"expected Processes payload within timeout"
|
|
);
|
|
if let Ok(AgentResponse::Processes(_)) = response {
|
|
// Success
|
|
} else {
|
|
panic!("expected Processes response");
|
|
}
|
|
}
|