use super::*;
#[test]
fn test_write_command_creates_lock_file() -> common::TestResult {
let temp_dir = init_project()?;
let _date = today();
let output = run_commands(
temp_dir.path(),
&[&["work", "new", "Test work item", "--active"]],
)?;
assert!(output.contains("Created work item"));
let lock_path = temp_dir.path().join("gov/.govctl.lock");
assert!(
lock_path.exists(),
"Lock file should exist after write command"
);
Ok(())
}
#[test]
fn test_sequential_write_commands_succeed() -> common::TestResult {
let temp_dir = init_project()?;
let _date = today();
let output = run_commands(
temp_dir.path(),
&[
&["work", "new", "First work item"],
&["work", "new", "Second work item"],
],
)?;
assert!(output.contains("Created work item"));
assert!(output.contains("exit: 0"));
Ok(())
}
#[test]
fn test_lock_file_location() -> common::TestResult {
let temp_dir = init_project()?;
let lock_path = temp_dir.path().join("gov/.govctl.lock");
let _ = fs::remove_file(&lock_path);
run_commands(temp_dir.path(), &[&["rfc", "new", "Test RFC"]])?;
assert!(
lock_path.exists(),
"Lock file should be created under gov root"
);
Ok(())
}
#[test]
fn test_read_commands_no_lock() -> common::TestResult {
let temp_dir = init_project()?;
let _date = today();
let lock_path = temp_dir.path().join("gov/.govctl.lock");
let _ = fs::remove_file(&lock_path);
run_commands(temp_dir.path(), &[&["status"]])?;
assert!(
!lock_path.exists(),
"Read commands should not create lock file"
);
run_commands(temp_dir.path(), &[&["check"]])?;
assert!(
!lock_path.exists(),
"Read commands should not create lock file"
);
run_commands(temp_dir.path(), &[&["loop", "list"]])?;
assert!(!lock_path.exists(), "Loop list should not create lock file");
Ok(())
}
#[test]
fn test_lock_timeout_configurable() -> common::TestResult {
let temp_dir = init_project()?;
create_config_with_timeout(temp_dir.path(), 1)?;
let output = run_commands(temp_dir.path(), &[&["work", "new", "Test"]])?;
assert!(output.contains("Created work item"));
Ok(())
}
#[test]
fn test_lock_released_after_write() -> common::TestResult {
let temp_dir = init_project()?;
let lock_path = temp_dir.path().join("gov/.govctl.lock");
let _ = fs::remove_file(&lock_path);
run_commands(temp_dir.path(), &[&["work", "new", "Test"]])?;
assert!(lock_path.exists(), "Lock file should exist");
let start = Instant::now();
let output = run_commands(temp_dir.path(), &[&["work", "new", "Test2"]])?;
let elapsed = start.elapsed();
assert!(
elapsed < Duration::from_secs(2),
"Second write should succeed immediately, took {:?}",
elapsed
);
assert!(output.contains("Created work item"));
Ok(())
}
#[test]
fn test_write_command_without_init_reports_missing_gov_root() -> common::TestResult {
let temp_dir = tempfile::TempDir::new()?;
let output = run_commands(temp_dir.path(), &[&["work", "new", "Needs init"]])?;
assert!(output.contains("exit: 1"), "output: {}", output);
assert!(output.contains("error[E0502]"), "output: {}", output);
assert!(
output.contains("Run 'govctl init' first"),
"output: {}",
output
);
Ok(())
}