use clap::Parser;
use crate::cli::{Cli, Command, RepairAction};
#[test]
fn cli_parses_repair_deploy() {
let cli = Cli::try_parse_from(["trusty-mpm", "repair", "deploy"]).unwrap();
match cli.command.unwrap() {
Command::Repair {
action: RepairAction::Deploy { force },
} => assert!(!force),
other => panic!("expected Command::Repair(Deploy), got {other:?}"),
}
}
#[test]
fn cli_parses_repair_push_guard() {
let cli = Cli::try_parse_from(["trusty-mpm", "repair", "push-guard"]).unwrap();
match cli.command.unwrap() {
Command::Repair {
action: RepairAction::PushGuard { path, dry_run },
} => {
assert_eq!(path, None, "the default target is the current directory");
assert!(!dry_run, "a bare invocation must actually install");
}
other => panic!("expected Command::Repair(PushGuard), got {other:?}"),
}
}
#[test]
fn cli_parses_repair_push_guard_flags() {
let cli = Cli::try_parse_from([
"trusty-mpm",
"repair",
"push-guard",
"--path",
"/tmp/some-clone",
"--dry-run",
])
.unwrap();
match cli.command.unwrap() {
Command::Repair {
action: RepairAction::PushGuard { path, dry_run },
} => {
assert_eq!(path, Some("/tmp/some-clone".to_string()));
assert!(dry_run);
}
other => panic!("expected Command::Repair(PushGuard), got {other:?}"),
}
}
#[test]
fn cli_parses_repair_session_store() {
let cli = Cli::try_parse_from(["trusty-mpm", "repair", "session-store"]).unwrap();
match cli.command.unwrap() {
Command::Repair {
action:
RepairAction::SessionStore {
path,
dry_run,
force,
},
} => {
assert_eq!(path, None, "the default target is the real store");
assert!(!dry_run, "a bare invocation actually repairs");
assert!(!force, "a bare invocation refuses an orphaned tail");
}
other => panic!("expected Command::Repair(SessionStore), got {other:?}"),
}
}
#[test]
fn cli_parses_repair_delegation() {
let cli =
Cli::try_parse_from(["trusty-mpm", "repair", "delegation", "af20cc838b2b30a55"]).unwrap();
match cli.command.unwrap() {
Command::Repair {
action: RepairAction::Delegation { agent_id, force },
} => {
assert_eq!(agent_id, "af20cc838b2b30a55");
assert!(
!force,
"a bare invocation must not assert the owner is gone"
);
}
other => panic!("expected Command::Repair(Delegation), got {other:?}"),
}
}
#[test]
fn cli_parses_repair_delegation_force() {
let cli = Cli::try_parse_from([
"trusty-mpm",
"repair",
"delegation",
"af20cc838b2b30a55",
"--force",
])
.unwrap();
match cli.command.unwrap() {
Command::Repair {
action: RepairAction::Delegation { force, .. },
} => assert!(force),
other => panic!("expected Command::Repair(Delegation), got {other:?}"),
}
}
#[test]
fn cli_parses_repair_savings_ledger() {
let cli = Cli::try_parse_from(["trusty-mpm", "repair", "savings-ledger"]).unwrap();
match cli.command.unwrap() {
Command::Repair {
action:
RepairAction::SavingsLedger {
root,
apply,
dry_run,
markers,
},
} => {
assert_eq!(root, None, "the default target is the real framework root");
assert!(!apply, "a bare invocation writes nothing");
assert!(!dry_run, "dry-run is the default, not a flag it must carry");
assert!(!markers, "a bare invocation leaves the markers alone");
}
other => panic!("expected Command::Repair(SavingsLedger), got {other:?}"),
}
}
#[test]
fn cli_parses_repair_savings_ledger_flags() {
let cli = Cli::try_parse_from([
"trusty-mpm",
"repair",
"savings-ledger",
"--root",
"/tmp/rehearsal",
"--apply",
"--markers",
])
.unwrap();
match cli.command.unwrap() {
Command::Repair {
action:
RepairAction::SavingsLedger {
root,
apply,
dry_run,
markers,
},
} => {
assert_eq!(root, Some("/tmp/rehearsal".to_string()));
assert!(apply);
assert!(!dry_run);
assert!(markers);
}
other => panic!("expected Command::Repair(SavingsLedger), got {other:?}"),
}
}
#[test]
fn cli_rejects_repair_savings_ledger_apply_with_dry_run() {
assert!(
Cli::try_parse_from([
"trusty-mpm",
"repair",
"savings-ledger",
"--apply",
"--dry-run",
])
.is_err(),
"--apply and --dry-run must not be combinable"
);
}
#[test]
fn cli_parses_repair_session_store_flags() {
let cli = Cli::try_parse_from([
"trusty-mpm",
"repair",
"session-store",
"--path",
"/tmp/sessions.json",
"--dry-run",
"--force",
])
.unwrap();
match cli.command.unwrap() {
Command::Repair {
action:
RepairAction::SessionStore {
path,
dry_run,
force,
},
} => {
assert_eq!(path, Some("/tmp/sessions.json".to_string()));
assert!(dry_run);
assert!(force);
}
other => panic!("expected Command::Repair(SessionStore), got {other:?}"),
}
}