diff --git a/src-tauri/creddy_cli/src/lib.rs b/src-tauri/creddy_cli/src/lib.rs index 9eaec77..94cfce0 100644 --- a/src-tauri/creddy_cli/src/lib.rs +++ b/src-tauri/creddy_cli/src/lib.rs @@ -9,8 +9,7 @@ pub use cli::{ invoke_shortcut, }; -pub(crate) use platform::connect; -pub use platform::server_addr; +pub use platform::{connect, server_addr}; pub mod proto; diff --git a/src-tauri/src/srv/mod.rs b/src-tauri/src/srv/mod.rs index d04f104..d671dfc 100644 --- a/src-tauri/src/srv/mod.rs +++ b/src-tauri/src/srv/mod.rs @@ -4,6 +4,7 @@ use tauri::{ AppHandle, async_runtime as rt, Manager, + Runtime, }; use tokio::io::AsyncReadExt; use tokio::sync::oneshot; @@ -80,9 +81,11 @@ impl<'s> CloseWaiter<'s> { } -fn serve(sock_name: &str, app_handle: AppHandle, handler: H) -> std::io::Result<()> - where H: Copy + Send + Fn(Stream, AppHandle, u32) -> F + 'static, +// note: AppHandle is generic over `Runtime` for testing +fn serve(sock_name: &str, app_handle: AppHandle, handler: H) -> std::io::Result<()> + where H: Copy + Send + Fn(Stream, AppHandle, u32) -> F + 'static, F: Send + Future>, + R: Runtime { let (mut listener, addr) = platform::bind(sock_name)?; rt::spawn(async move { @@ -233,23 +236,21 @@ mod tests { #[tokio::test] async fn test_server_connect() { let app = tauri::test::mock_app(); - serve("creddy_server_test", app.app_handle().clone(), |stream, _handle, _pid| { + serve("creddy_server_test", app.app_handle().clone(), |mut stream, _handle, _pid| { async move { let buf = serde_json::to_vec(&CliResponse::Empty).unwrap(); stream.write_all(&buf).await.unwrap(); Ok(()) } - }); + }).unwrap(); let addr = creddy_cli::server_addr("creddy_server_test"); let mut stream = creddy_cli::connect(Some(addr)).await.unwrap(); - let req = CliRequest::InvokeShortcut{ action: ShortcutAction::ShowWindow }; - let req_bytes = serde_json::to_vec(&req).unwrap(); - stream.write_all(&req_bytes).await.unwrap(); let mut buf = Vec::new(); stream.read_to_end(&mut buf).await.unwrap(); let resp: CliResponse = serde_json::from_slice(&buf).unwrap(); + assert!(matches!(resp, CliResponse::Empty)) } }