Squashed 'components/zinit/' content from commit 1b76c06
git-subtree-dir: components/zinit git-subtree-split: 1b76c062fe31d552d1b7b23484ce163995a81482
This commit is contained in:
66
zinit-client/tests/integration_test.rs
Normal file
66
zinit-client/tests/integration_test.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
use std::env;
|
||||
use zinit_client::{Client, ClientError};
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_connection_error() {
|
||||
// Try to connect to a non-existent socket
|
||||
let result = Client::unix_socket("/non/existent/socket").await;
|
||||
assert!(result.is_ok()); // Just creating the client succeeds
|
||||
|
||||
// Trying to make a request should fail
|
||||
if let Ok(client) = result {
|
||||
let list_result = client.list().await;
|
||||
assert!(matches!(list_result, Err(ClientError::ConnectionError(_))));
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_http_connection_error() {
|
||||
// Try to connect to a non-existent HTTP endpoint
|
||||
let result = Client::http("http://localhost:12345").await;
|
||||
// This should succeed as we're just creating the client, not making a request
|
||||
assert!(result.is_ok());
|
||||
|
||||
// Try to make a request which should fail
|
||||
if let Ok(client) = result {
|
||||
let list_result = client.list().await;
|
||||
assert!(matches!(list_result, Err(ClientError::ConnectionError(_))));
|
||||
}
|
||||
}
|
||||
|
||||
// This test only runs if ZINIT_SOCKET is set in the environment
|
||||
// and points to a valid Zinit socket
|
||||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn test_live_connection() {
|
||||
let socket_path = match env::var("ZINIT_SOCKET") {
|
||||
Ok(path) => path,
|
||||
Err(_) => {
|
||||
println!("ZINIT_SOCKET not set, skipping live test");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let client = match Client::unix_socket(&socket_path).await {
|
||||
Ok(client) => client,
|
||||
Err(e) => {
|
||||
panic!(
|
||||
"Failed to connect to Zinit socket at {}: {}",
|
||||
socket_path, e
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// Test listing services
|
||||
let services = client.list().await.expect("Failed to list services");
|
||||
println!("Found {} services", services.len());
|
||||
|
||||
// If there are services, test getting status of the first one
|
||||
if let Some((service_name, _)) = services.iter().next() {
|
||||
let status = client
|
||||
.status(service_name)
|
||||
.await
|
||||
.expect("Failed to get service status");
|
||||
println!("Service {} has PID {}", service_name, status.pid);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user