Compare commits
2 Commits
4c18de8b7a
...
efbf6c687c
Author | SHA1 | Date | |
---|---|---|---|
efbf6c687c | |||
ee495478ff |
@ -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"] }
|
tauri = { version = "2.0.0-beta", features = ["tray-icon", "test"] }
|
||||||
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"
|
||||||
|
@ -9,8 +9,7 @@ pub use cli::{
|
|||||||
invoke_shortcut,
|
invoke_shortcut,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) use platform::connect;
|
pub use platform::{connect, server_addr};
|
||||||
pub use platform::server_addr;
|
|
||||||
|
|
||||||
pub mod proto;
|
pub mod proto;
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ 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;
|
||||||
@ -80,9 +81,11 @@ impl<'s> CloseWaiter<'s> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn serve<H, F>(sock_name: &str, app_handle: AppHandle, handler: H) -> std::io::Result<()>
|
// note: AppHandle is generic over `Runtime` for testing
|
||||||
where H: Copy + Send + Fn(Stream, AppHandle, u32) -> F + 'static,
|
fn serve<H, F, R>(sock_name: &str, app_handle: AppHandle<R>, handler: H) -> std::io::Result<()>
|
||||||
|
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 {
|
||||||
@ -223,3 +226,31 @@ 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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user