Skip to content
This repository was archived by the owner on Dec 15, 2025. It is now read-only.

Commit 257d02a

Browse files
committed
fix formatting
1 parent b939882 commit 257d02a

11 files changed

Lines changed: 414 additions & 371 deletions

File tree

src/app/api.rs

Lines changed: 72 additions & 64 deletions
Large diffs are not rendered by default.

src/bin/testapp.rs

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
extern crate zinit;
22

33
use anyhow::Result;
4-
use std::path::Path;
5-
use tokio::time::{sleep, Duration};
64
use std::env;
5+
use tokio::time::{sleep, Duration};
76

87
use zinit::app::api::Client;
98
use zinit::testapp;
@@ -12,8 +11,16 @@ use zinit::testapp;
1211
async fn main() -> Result<()> {
1312
// Define paths for socket and config
1413
let temp_dir = env::temp_dir();
15-
let socket_path = temp_dir.join("zinit-test.sock").to_str().unwrap().to_string();
16-
let config_dir = temp_dir.join("zinit-test-config").to_str().unwrap().to_string();
14+
let socket_path = temp_dir
15+
.join("zinit-test.sock")
16+
.to_str()
17+
.unwrap()
18+
.to_string();
19+
let config_dir = temp_dir
20+
.join("zinit-test-config")
21+
.to_str()
22+
.unwrap()
23+
.to_string();
1724

1825
println!("Starting zinit with socket at: {}", socket_path);
1926
println!("Using config directory: {}", config_dir);
@@ -29,16 +36,22 @@ async fn main() -> Result<()> {
2936

3037
// Create service configurations
3138
println!("Creating service configurations...");
32-
39+
3340
// Create a find service
34-
testapp::create_service_config(&config_dir, "find-service", "find / -name \"*.txt\" -type f").await?;
35-
41+
testapp::create_service_config(
42+
&config_dir,
43+
"find-service",
44+
"find / -name \"*.txt\" -type f",
45+
)
46+
.await?;
47+
3648
// Create a sleep service with echo
3749
testapp::create_service_config(
38-
&config_dir,
39-
"sleep-service",
40-
"sh -c 'echo Starting sleep; sleep 30; echo Finished sleep'"
41-
).await?;
50+
&config_dir,
51+
"sleep-service",
52+
"sh -c 'echo Starting sleep; sleep 30; echo Finished sleep'",
53+
)
54+
.await?;
4255

4356
// Wait for zinit to load the configurations
4457
sleep(Duration::from_secs(1)).await;
@@ -58,7 +71,7 @@ async fn main() -> Result<()> {
5871
// Start the find service
5972
println!("\nStarting find-service...");
6073
client.start("find-service").await?;
61-
74+
6275
// Wait a bit and check status
6376
sleep(Duration::from_secs(2)).await;
6477
let status = client.status("find-service").await?;
@@ -67,7 +80,7 @@ async fn main() -> Result<()> {
6780
// Start the sleep service
6881
println!("\nStarting sleep-service...");
6982
client.start("sleep-service").await?;
70-
83+
7184
// Wait a bit and check status
7285
sleep(Duration::from_secs(2)).await;
7386
let status = client.status("sleep-service").await?;
@@ -76,7 +89,7 @@ async fn main() -> Result<()> {
7689
// Stop the find service
7790
println!("\nStopping find-service...");
7891
client.stop("find-service").await?;
79-
92+
8093
// Wait a bit and check status
8194
sleep(Duration::from_secs(2)).await;
8295
let status = client.status("find-service").await?;
@@ -85,15 +98,16 @@ async fn main() -> Result<()> {
8598
// Kill the sleep service with SIGTERM
8699
println!("\nKilling sleep-service with SIGTERM...");
87100
client.kill("sleep-service", "SIGTERM").await?;
88-
101+
89102
// Wait a bit and check status
90103
sleep(Duration::from_secs(2)).await;
91104
let status = client.status("sleep-service").await?;
92105
println!("sleep-service status after killing: {:?}", status);
93106

94107
// Cleanup - forget services
95108
println!("\nForgetting services...");
96-
if status.pid == 0 { // Only forget if it's not running
109+
if status.pid == 0 {
110+
// Only forget if it's not running
97111
client.forget("sleep-service").await?;
98112
}
99113
client.forget("find-service").await?;
@@ -104,4 +118,4 @@ async fn main() -> Result<()> {
104118

105119
println!("\nTest completed successfully!");
106120
Ok(())
107-
}
121+
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ extern crate tokio;
77

88
pub mod app;
99
pub mod manager;
10+
pub mod testapp;
1011
pub mod zinit;
11-
pub mod testapp;

src/testapp/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use anyhow::Result;
2+
use std::env;
23
use std::path::Path;
4+
use std::process::Stdio;
35
use tokio::process::Command;
46
use tokio::time::{sleep, Duration};
5-
use std::process::Stdio;
6-
use std::env;
77

88
pub async fn start_zinit(socket_path: &str, config_dir: &str) -> Result<()> {
99
// Create a temporary config directory if it doesn't exist
@@ -27,12 +27,12 @@ pub async fn start_zinit(socket_path: &str, config_dir: &str) -> Result<()> {
2727
.stderr(Stdio::piped());
2828

2929
let child = cmd.spawn()?;
30-
30+
3131
// Give zinit some time to start up
3232
sleep(Duration::from_secs(1)).await;
33-
33+
3434
println!("Zinit started with PID: {:?}", child.id());
35-
35+
3636
Ok(())
3737
}
3838

@@ -54,4 +54,4 @@ dir: /
5454

5555
tokio::fs::write(config_path, config_content).await?;
5656
Ok(())
57-
}
57+
}

src/zinit/errors.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,22 @@ impl ZInitError {
5959

6060
/// Create a new InvalidStateTransition error
6161
pub fn invalid_state_transition<S: Into<String>>(message: S) -> Self {
62-
ZInitError::InvalidStateTransition { message: message.into() }
62+
ZInitError::InvalidStateTransition {
63+
message: message.into(),
64+
}
6365
}
6466

6567
/// Create a new DependencyError error
6668
pub fn dependency_error<S: Into<String>>(message: S) -> Self {
67-
ZInitError::DependencyError { message: message.into() }
69+
ZInitError::DependencyError {
70+
message: message.into(),
71+
}
6872
}
6973

7074
/// Create a new ProcessError error
7175
pub fn process_error<S: Into<String>>(message: S) -> Self {
72-
ZInitError::ProcessError { message: message.into() }
76+
ZInitError::ProcessError {
77+
message: message.into(),
78+
}
7379
}
74-
}
80+
}

0 commit comments

Comments
 (0)