aboutsummaryrefslogtreecommitdiff
path: root/tests/cli.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cli.rs')
-rw-r--r--tests/cli.rs50
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 @@
1use assert_cmd::Command; 1use assert_cmd::Command;
2use predicates::prelude::*; 2use predicates::prelude::*;
3use std::fs; 3use std::fs;
4use std::path::PathBuf;
4use std::time::Duration; 5use std::time::Duration;
5use tempfile::TempDir; 6use 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]
343fn 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]
343fn test_run_with_complex_command() { 389fn test_run_with_complex_command() {
344 let temp_dir = TempDir::new().unwrap(); 390 let temp_dir = TempDir::new().unwrap();
345 391