test: add test with js server (#65)
This commit is contained in:
parent
d6fb12b69f
commit
ac1b8c6ddb
1 changed files with 68 additions and 2 deletions
|
|
@ -1,4 +1,7 @@
|
|||
use rmcp::transport::sse_server::SseServer;
|
||||
use rmcp::{
|
||||
ServiceExt,
|
||||
transport::{SseServer, TokioChildProcess},
|
||||
};
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
mod common;
|
||||
use common::calculator::Calculator;
|
||||
|
|
@ -34,3 +37,32 @@ async fn test_with_js_client() -> anyhow::Result<()> {
|
|||
ct.cancel();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_with_js_server() -> anyhow::Result<()> {
|
||||
let _ = tracing_subscriber::registry()
|
||||
.with(
|
||||
tracing_subscriber::EnvFilter::try_from_default_env()
|
||||
.unwrap_or_else(|_| "debug".to_string().into()),
|
||||
)
|
||||
.with(tracing_subscriber::fmt::layer())
|
||||
.try_init();
|
||||
tokio::process::Command::new("npm")
|
||||
.arg("install")
|
||||
.current_dir("tests/test_with_js")
|
||||
.spawn()?
|
||||
.wait()
|
||||
.await?;
|
||||
let transport = TokioChildProcess::new(
|
||||
tokio::process::Command::new("node").arg("tests/test_with_js/server.js"),
|
||||
)?;
|
||||
|
||||
let client = ().serve(transport).await?;
|
||||
let resources = client.list_all_resources().await?;
|
||||
tracing::info!("{:#?}", resources);
|
||||
let tools = client.list_all_tools().await?;
|
||||
tracing::info!("{:#?}", tools);
|
||||
|
||||
client.cancel().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue