diff options
| -rw-r--r-- | tests/cli.rs | 60 |
1 files changed, 56 insertions, 4 deletions
diff --git a/tests/cli.rs b/tests/cli.rs index 37ceb7f..005468c 100644 --- a/tests/cli.rs +++ b/tests/cli.rs | |||
| @@ -267,15 +267,21 @@ fn test_clean_with_orphans() { | |||
| 267 | 267 | ||
| 268 | // Create a dead process | 268 | // Create a dead process |
| 269 | let mut cmd = Command::cargo_bin("demon").unwrap(); | 269 | let mut cmd = Command::cargo_bin("demon").unwrap(); |
| 270 | cmd.args(["--root-dir", temp_dir.path().to_str().unwrap()]) | 270 | cmd.args(&["run", "--root-dir", temp_dir.path().to_str().unwrap(), "dead", "echo", "hello"]) |
| 271 | .args(&["run", "dead", "echo", "hello"]) | ||
| 272 | .assert() | 271 | .assert() |
| 273 | .success(); | 272 | .success(); |
| 274 | 273 | ||
| 274 | // Wait for process to complete | ||
| 275 | std::thread::sleep(Duration::from_millis(100)); | ||
| 276 | |||
| 277 | // Verify files exist before clean | ||
| 278 | assert!(temp_dir.path().join("dead.pid").exists()); | ||
| 279 | assert!(temp_dir.path().join("dead.stdout").exists()); | ||
| 280 | assert!(temp_dir.path().join("dead.stderr").exists()); | ||
| 281 | |||
| 275 | // Clean up orphaned files | 282 | // Clean up orphaned files |
| 276 | let mut cmd = Command::cargo_bin("demon").unwrap(); | 283 | let mut cmd = Command::cargo_bin("demon").unwrap(); |
| 277 | cmd.args(["--root-dir", temp_dir.path().to_str().unwrap()]) | 284 | cmd.args(&["clean", "--root-dir", temp_dir.path().to_str().unwrap()]) |
| 278 | .args(&["clean"]) | ||
| 279 | .assert() | 285 | .assert() |
| 280 | .success() | 286 | .success() |
| 281 | .stdout(predicate::str::contains("Cleaned up")) | 287 | .stdout(predicate::str::contains("Cleaned up")) |
| @@ -288,6 +294,52 @@ fn test_clean_with_orphans() { | |||
| 288 | } | 294 | } |
| 289 | 295 | ||
| 290 | #[test] | 296 | #[test] |
| 297 | fn test_clean_removes_stdout_stderr_files() { | ||
| 298 | let temp_dir = TempDir::new().unwrap(); | ||
| 299 | |||
| 300 | // Create a process that outputs to both stdout and stderr | ||
| 301 | let mut cmd = Command::cargo_bin("demon").unwrap(); | ||
| 302 | cmd.args(&[ | ||
| 303 | "run", | ||
| 304 | "--root-dir", | ||
| 305 | temp_dir.path().to_str().unwrap(), | ||
| 306 | "test_output", | ||
| 307 | "--", | ||
| 308 | "sh", | ||
| 309 | "-c", | ||
| 310 | "echo 'stdout content'; echo 'stderr content' >&2" | ||
| 311 | ]) | ||
| 312 | .assert() | ||
| 313 | .success(); | ||
| 314 | |||
| 315 | // Wait for process to complete | ||
| 316 | std::thread::sleep(Duration::from_millis(100)); | ||
| 317 | |||
| 318 | // Verify all files exist and have content | ||
| 319 | assert!(temp_dir.path().join("test_output.pid").exists()); | ||
| 320 | assert!(temp_dir.path().join("test_output.stdout").exists()); | ||
| 321 | assert!(temp_dir.path().join("test_output.stderr").exists()); | ||
| 322 | |||
| 323 | let stdout_content = fs::read_to_string(temp_dir.path().join("test_output.stdout")).unwrap(); | ||
| 324 | let stderr_content = fs::read_to_string(temp_dir.path().join("test_output.stderr")).unwrap(); | ||
| 325 | assert!(stdout_content.contains("stdout content")); | ||
| 326 | assert!(stderr_content.contains("stderr content")); | ||
| 327 | |||
| 328 | // Clean up orphaned files | ||
| 329 | let mut cmd = Command::cargo_bin("demon").unwrap(); | ||
| 330 | cmd.args(&["clean", "--root-dir", temp_dir.path().to_str().unwrap()]) | ||
| 331 | .assert() | ||
| 332 | .success() | ||
| 333 | .stdout(predicate::str::contains("Cleaned up")) | ||
| 334 | .stdout(predicate::str::contains("orphaned")); | ||
| 335 | |||
| 336 | // Verify ALL files are gone, not just the PID file | ||
| 337 | assert!(!temp_dir.path().join("test_output.pid").exists()); | ||
| 338 | assert!(!temp_dir.path().join("test_output.stdout").exists()); | ||
| 339 | assert!(!temp_dir.path().join("test_output.stderr").exists()); | ||
| 340 | } | ||
| 341 | |||
| 342 | #[test] | ||
| 291 | fn test_run_with_complex_command() { | 343 | fn test_run_with_complex_command() { |
| 292 | let temp_dir = TempDir::new().unwrap(); | 344 | let temp_dir = TempDir::new().unwrap(); |
| 293 | 345 | ||
