aboutsummaryrefslogtreecommitdiff
path: root/tests/cli.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cli.rs')
-rw-r--r--tests/cli.rs78
1 files changed, 52 insertions, 26 deletions
diff --git a/tests/cli.rs b/tests/cli.rs
index b97d331..deaa3f0 100644
--- a/tests/cli.rs
+++ b/tests/cli.rs
@@ -36,10 +36,15 @@ fn test_run_missing_command() {
36 let temp_dir = TempDir::new().unwrap(); 36 let temp_dir = TempDir::new().unwrap();
37 37
38 let mut cmd = Command::cargo_bin("demon").unwrap(); 38 let mut cmd = Command::cargo_bin("demon").unwrap();
39 cmd.args(&["run", "--root-dir", temp_dir.path().to_str().unwrap(), "test"]) 39 cmd.args(&[
40 .assert() 40 "run",
41 .failure() 41 "--root-dir",
42 .stderr(predicate::str::contains("Command cannot be empty")); 42 temp_dir.path().to_str().unwrap(),
43 "test",
44 ])
45 .assert()
46 .failure()
47 .stderr(predicate::str::contains("Command cannot be empty"));
43} 48}
44 49
45#[test] 50#[test]
@@ -47,10 +52,17 @@ fn test_run_creates_files() {
47 let temp_dir = TempDir::new().unwrap(); 52 let temp_dir = TempDir::new().unwrap();
48 53
49 let mut cmd = Command::cargo_bin("demon").unwrap(); 54 let mut cmd = Command::cargo_bin("demon").unwrap();
50 cmd.args(&["run", "--root-dir", temp_dir.path().to_str().unwrap(), "test", "echo", "hello"]) 55 cmd.args(&[
51 .assert() 56 "run",
52 .success() 57 "--root-dir",
53 .stdout(predicate::str::contains("Started daemon 'test'")); 58 temp_dir.path().to_str().unwrap(),
59 "test",
60 "echo",
61 "hello",
62 ])
63 .assert()
64 .success()
65 .stdout(predicate::str::contains("Started daemon 'test'"));
54 66
55 // Verify files were created 67 // Verify files were created
56 assert!(temp_dir.path().join("test.pid").exists()); 68 assert!(temp_dir.path().join("test.pid").exists());
@@ -71,9 +83,16 @@ fn test_run_duplicate_process() {
71 83
72 // Start a long-running process 84 // Start a long-running process
73 let mut cmd = Command::cargo_bin("demon").unwrap(); 85 let mut cmd = Command::cargo_bin("demon").unwrap();
74 cmd.args(&["run", "--root-dir", temp_dir.path().to_str().unwrap(), "long", "sleep", "30"]) 86 cmd.args(&[
75 .assert() 87 "run",
76 .success(); 88 "--root-dir",
89 temp_dir.path().to_str().unwrap(),
90 "long",
91 "sleep",
92 "30",
93 ])
94 .assert()
95 .success();
77 96
78 // Try to start another with the same ID 97 // Try to start another with the same ID
79 let mut cmd = Command::cargo_bin("demon").unwrap(); 98 let mut cmd = Command::cargo_bin("demon").unwrap();
@@ -267,9 +286,16 @@ fn test_clean_with_orphans() {
267 286
268 // Create a dead process 287 // Create a dead process
269 let mut cmd = Command::cargo_bin("demon").unwrap(); 288 let mut cmd = Command::cargo_bin("demon").unwrap();
270 cmd.args(&["run", "--root-dir", temp_dir.path().to_str().unwrap(), "dead", "echo", "hello"]) 289 cmd.args(&[
271 .assert() 290 "run",
272 .success(); 291 "--root-dir",
292 temp_dir.path().to_str().unwrap(),
293 "dead",
294 "echo",
295 "hello",
296 ])
297 .assert()
298 .success();
273 299
274 // Wait for process to complete 300 // Wait for process to complete
275 std::thread::sleep(Duration::from_millis(100)); 301 std::thread::sleep(Duration::from_millis(100));
@@ -300,14 +326,14 @@ fn test_clean_removes_stdout_stderr_files() {
300 // Create a process that outputs to both stdout and stderr 326 // Create a process that outputs to both stdout and stderr
301 let mut cmd = Command::cargo_bin("demon").unwrap(); 327 let mut cmd = Command::cargo_bin("demon").unwrap();
302 cmd.args(&[ 328 cmd.args(&[
303 "run", 329 "run",
304 "--root-dir", 330 "--root-dir",
305 temp_dir.path().to_str().unwrap(), 331 temp_dir.path().to_str().unwrap(),
306 "test_output", 332 "test_output",
307 "--", 333 "--",
308 "sh", 334 "sh",
309 "-c", 335 "-c",
310 "echo 'stdout content'; echo 'stderr content' >&2" 336 "echo 'stdout content'; echo 'stderr content' >&2",
311 ]) 337 ])
312 .assert() 338 .assert()
313 .success(); 339 .success();
@@ -319,7 +345,7 @@ fn test_clean_removes_stdout_stderr_files() {
319 assert!(temp_dir.path().join("test_output.pid").exists()); 345 assert!(temp_dir.path().join("test_output.pid").exists());
320 assert!(temp_dir.path().join("test_output.stdout").exists()); 346 assert!(temp_dir.path().join("test_output.stdout").exists());
321 assert!(temp_dir.path().join("test_output.stderr").exists()); 347 assert!(temp_dir.path().join("test_output.stderr").exists());
322 348
323 let stdout_content = fs::read_to_string(temp_dir.path().join("test_output.stdout")).unwrap(); 349 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(); 350 let stderr_content = fs::read_to_string(temp_dir.path().join("test_output.stderr")).unwrap();
325 assert!(stdout_content.contains("stdout content")); 351 assert!(stdout_content.contains("stdout content"));
@@ -343,16 +369,16 @@ fn test_clean_removes_stdout_stderr_files() {
343fn test_default_demon_directory_creation() { 369fn test_default_demon_directory_creation() {
344 // This test verifies that when no --root-dir is specified, 370 // This test verifies that when no --root-dir is specified,
345 // the system creates and uses a .demon subdirectory in the git root 371 // the system creates and uses a .demon subdirectory in the git root
346 372
347 // Create a temporary git repo 373 // Create a temporary git repo
348 let temp_dir = TempDir::new().unwrap(); 374 let temp_dir = TempDir::new().unwrap();
349 let git_dir = temp_dir.path().join(".git"); 375 let git_dir = temp_dir.path().join(".git");
350 std::fs::create_dir(&git_dir).unwrap(); 376 std::fs::create_dir(&git_dir).unwrap();
351 377
352 // Change to the temp directory 378 // Change to the temp directory
353 let original_dir = std::env::current_dir().unwrap(); 379 let original_dir = std::env::current_dir().unwrap();
354 std::env::set_current_dir(temp_dir.path()).unwrap(); 380 std::env::set_current_dir(temp_dir.path()).unwrap();
355 381
356 // Restore directory when done 382 // Restore directory when done
357 struct DirGuard(PathBuf); 383 struct DirGuard(PathBuf);
358 impl Drop for DirGuard { 384 impl Drop for DirGuard {
@@ -361,17 +387,17 @@ fn test_default_demon_directory_creation() {
361 } 387 }
362 } 388 }
363 let _guard = DirGuard(original_dir); 389 let _guard = DirGuard(original_dir);
364 390
365 // Run a command without --root-dir to test default behavior 391 // Run a command without --root-dir to test default behavior
366 let mut cmd = Command::cargo_bin("demon").unwrap(); 392 let mut cmd = Command::cargo_bin("demon").unwrap();
367 cmd.args(&["run", "default_test", "echo", "hello"]) 393 cmd.args(&["run", "default_test", "echo", "hello"])
368 .assert() 394 .assert()
369 .success() 395 .success()
370 .stdout(predicate::str::contains("Started daemon 'default_test'")); 396 .stdout(predicate::str::contains("Started daemon 'default_test'"));
371 397
372 // Wait for process to complete 398 // Wait for process to complete
373 std::thread::sleep(Duration::from_millis(100)); 399 std::thread::sleep(Duration::from_millis(100));
374 400
375 // Verify that .demon directory was created and files are in it 401 // Verify that .demon directory was created and files are in it
376 let demon_dir = temp_dir.path().join(".demon"); 402 let demon_dir = temp_dir.path().join(".demon");
377 assert!(demon_dir.exists()); 403 assert!(demon_dir.exists());
@@ -379,7 +405,7 @@ fn test_default_demon_directory_creation() {
379 assert!(demon_dir.join("default_test.pid").exists()); 405 assert!(demon_dir.join("default_test.pid").exists());
380 assert!(demon_dir.join("default_test.stdout").exists()); 406 assert!(demon_dir.join("default_test.stdout").exists());
381 assert!(demon_dir.join("default_test.stderr").exists()); 407 assert!(demon_dir.join("default_test.stderr").exists());
382 408
383 // Verify the stdout content 409 // Verify the stdout content
384 let stdout_content = fs::read_to_string(demon_dir.join("default_test.stdout")).unwrap(); 410 let stdout_content = fs::read_to_string(demon_dir.join("default_test.stdout")).unwrap();
385 assert_eq!(stdout_content.trim(), "hello"); 411 assert_eq!(stdout_content.trim(), "hello");