start working on test for server address

This commit is contained in:
Joseph Montanaro 2024-12-27 15:50:08 -05:00
parent 4c18de8b7a
commit ee495478ff
2 changed files with 31 additions and 1 deletions

View File

@ -30,7 +30,7 @@ tauri-build = { version = "2.0.0-beta", features = [] }
[dependencies]
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"
sysinfo = "0.26.8"
aws-config = "1.5.3"

View File

@ -223,3 +223,33 @@ mod platform {
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(), |stream, _handle, _pid| {
async move {
let buf = serde_json::to_vec(&CliResponse::Empty).unwrap();
stream.write_all(&buf).await.unwrap();
Ok(())
}
});
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))
}
}