Compare commits

..

No commits in common. "efbf6c687c38f14926bb27e9e927645c41e36c85" and "4c18de8b7a48100be564265bf7f759aa95d44e51" have entirely different histories.

3 changed files with 5 additions and 35 deletions

View File

@ -30,7 +30,7 @@ tauri-build = { version = "2.0.0-beta", features = [] }
[dependencies] [dependencies]
creddy_cli = { path = "./creddy_cli" } creddy_cli = { path = "./creddy_cli" }
tauri = { version = "2.0.0-beta", features = ["tray-icon", "test"] } tauri = { version = "2.0.0-beta", features = ["tray-icon"] }
sodiumoxide = "0.2.7" sodiumoxide = "0.2.7"
sysinfo = "0.26.8" sysinfo = "0.26.8"
aws-config = "1.5.3" aws-config = "1.5.3"

View File

@ -9,7 +9,8 @@ pub use cli::{
invoke_shortcut, invoke_shortcut,
}; };
pub use platform::{connect, server_addr}; pub(crate) use platform::connect;
pub use platform::server_addr;
pub mod proto; pub mod proto;

View File

@ -4,7 +4,6 @@ use tauri::{
AppHandle, AppHandle,
async_runtime as rt, async_runtime as rt,
Manager, Manager,
Runtime,
}; };
use tokio::io::AsyncReadExt; use tokio::io::AsyncReadExt;
use tokio::sync::oneshot; use tokio::sync::oneshot;
@ -81,11 +80,9 @@ impl<'s> CloseWaiter<'s> {
} }
// note: AppHandle is generic over `Runtime` for testing fn serve<H, F>(sock_name: &str, app_handle: AppHandle, handler: H) -> std::io::Result<()>
fn serve<H, F, R>(sock_name: &str, app_handle: AppHandle<R>, handler: H) -> std::io::Result<()> where H: Copy + Send + Fn(Stream, AppHandle, u32) -> F + 'static,
where H: Copy + Send + Fn(Stream, AppHandle<R>, u32) -> F + 'static,
F: Send + Future<Output = Result<(), HandlerError>>, F: Send + Future<Output = Result<(), HandlerError>>,
R: Runtime
{ {
let (mut listener, addr) = platform::bind(sock_name)?; let (mut listener, addr) = platform::bind(sock_name)?;
rt::spawn(async move { rt::spawn(async move {
@ -226,31 +223,3 @@ mod platform {
Ok((stream, pid)) Ok((stream, pid))
} }
} }
#[cfg(test)]
mod tests {
use super::*;
use tokio::io::AsyncWriteExt;
#[tokio::test]
async fn test_server_connect() {
let app = tauri::test::mock_app();
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 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))
}
}