diff options
| author | diogo464 <[email protected]> | 2025-06-22 22:15:14 +0100 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-06-22 22:15:14 +0100 |
| commit | ea62efa29f99791030c6e486955580051ced3e29 (patch) | |
| tree | 73ee85d06eefd7ee3fc4998f81a69abcdc3e3e5e /tests/cli.rs | |
| parent | 2b4bca30e88f99b803911dbbc9764d7e9a447d31 (diff) | |
Change default root directory to use .demon subdirectory
- Modified find_git_root() to create and return <git_root>/.demon instead of <git_root>
- Auto-creates .demon directory if it doesn't exist
- Added proper error handling for edge cases (file vs directory conflicts, permissions)
- Maintains backward compatibility with explicit --root-dir flag
- Added comprehensive test to verify new default behavior
- Fixed test argument ordering for test_list_empty
Files are now organized as:
- Before: /project/daemon.pid, /project/daemon.stdout, /project/daemon.stderr
- After: /project/.demon/daemon.pid, /project/.demon/daemon.stdout, /project/.demon/daemon.stderr
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
Diffstat (limited to 'tests/cli.rs')
| -rw-r--r-- | tests/cli.rs | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/tests/cli.rs b/tests/cli.rs index 005468c..b97d331 100644 --- a/tests/cli.rs +++ b/tests/cli.rs | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | use assert_cmd::Command; | 1 | use assert_cmd::Command; |
| 2 | use predicates::prelude::*; | 2 | use predicates::prelude::*; |
| 3 | use std::fs; | 3 | use std::fs; |
| 4 | use std::path::PathBuf; | ||
| 4 | use std::time::Duration; | 5 | use std::time::Duration; |
| 5 | use tempfile::TempDir; | 6 | use tempfile::TempDir; |
| 6 | 7 | ||
| @@ -95,8 +96,7 @@ fn test_list_empty() { | |||
| 95 | let temp_dir = TempDir::new().unwrap(); | 96 | let temp_dir = TempDir::new().unwrap(); |
| 96 | 97 | ||
| 97 | let mut cmd = Command::cargo_bin("demon").unwrap(); | 98 | let mut cmd = Command::cargo_bin("demon").unwrap(); |
| 98 | cmd.args(["--root-dir", temp_dir.path().to_str().unwrap()]) | 99 | cmd.args(&["list", "--root-dir", temp_dir.path().to_str().unwrap()]) |
| 99 | .args(&["list"]) | ||
| 100 | .assert() | 100 | .assert() |
| 101 | .success() | 101 | .success() |
| 102 | .stdout(predicate::str::contains("ID")) | 102 | .stdout(predicate::str::contains("ID")) |
| @@ -340,6 +340,52 @@ fn test_clean_removes_stdout_stderr_files() { | |||
| 340 | } | 340 | } |
| 341 | 341 | ||
| 342 | #[test] | 342 | #[test] |
| 343 | fn test_default_demon_directory_creation() { | ||
| 344 | // This test verifies that when no --root-dir is specified, | ||
| 345 | // the system creates and uses a .demon subdirectory in the git root | ||
| 346 | |||
| 347 | // Create a temporary git repo | ||
| 348 | let temp_dir = TempDir::new().unwrap(); | ||
| 349 | let git_dir = temp_dir.path().join(".git"); | ||
| 350 | std::fs::create_dir(&git_dir).unwrap(); | ||
| 351 | |||
| 352 | // Change to the temp directory | ||
| 353 | let original_dir = std::env::current_dir().unwrap(); | ||
| 354 | std::env::set_current_dir(temp_dir.path()).unwrap(); | ||
| 355 | |||
| 356 | // Restore directory when done | ||
| 357 | struct DirGuard(PathBuf); | ||
| 358 | impl Drop for DirGuard { | ||
| 359 | fn drop(&mut self) { | ||
| 360 | let _ = std::env::set_current_dir(&self.0); | ||
| 361 | } | ||
| 362 | } | ||
| 363 | let _guard = DirGuard(original_dir); | ||
| 364 | |||
| 365 | // Run a command without --root-dir to test default behavior | ||
| 366 | let mut cmd = Command::cargo_bin("demon").unwrap(); | ||
| 367 | cmd.args(&["run", "default_test", "echo", "hello"]) | ||
| 368 | .assert() | ||
| 369 | .success() | ||
| 370 | .stdout(predicate::str::contains("Started daemon 'default_test'")); | ||
| 371 | |||
| 372 | // Wait for process to complete | ||
| 373 | std::thread::sleep(Duration::from_millis(100)); | ||
| 374 | |||
| 375 | // Verify that .demon directory was created and files are in it | ||
| 376 | let demon_dir = temp_dir.path().join(".demon"); | ||
| 377 | assert!(demon_dir.exists()); | ||
| 378 | assert!(demon_dir.is_dir()); | ||
| 379 | assert!(demon_dir.join("default_test.pid").exists()); | ||
| 380 | assert!(demon_dir.join("default_test.stdout").exists()); | ||
| 381 | assert!(demon_dir.join("default_test.stderr").exists()); | ||
| 382 | |||
| 383 | // Verify the stdout content | ||
| 384 | let stdout_content = fs::read_to_string(demon_dir.join("default_test.stdout")).unwrap(); | ||
| 385 | assert_eq!(stdout_content.trim(), "hello"); | ||
| 386 | } | ||
| 387 | |||
| 388 | #[test] | ||
| 343 | fn test_run_with_complex_command() { | 389 | fn test_run_with_complex_command() { |
| 344 | let temp_dir = TempDir::new().unwrap(); | 390 | let temp_dir = TempDir::new().unwrap(); |
| 345 | 391 | ||
