use super::*;
#[test]
fn every_exempt_verb_is_one_of_the_documented_recovery_verbs() {
for command in [
Commands::Kill,
Commands::Ping,
Commands::Daemon(daemon_args(Some(cli::DaemonCmd::Reload))),
] {
let verb =
recovery_verb(&command).unwrap_or_else(|| panic!("{command:?} must stay exempt"));
assert!(
RECOVERY_VERBS.contains(&verb),
"{verb} is exempt but undocumented"
);
}
assert_eq!(
recovery_verb(&Commands::Daemon(daemon_args(Some(cli::DaemonCmd::Reload)))),
Some("daemon reload"),
"the verb the skew refusal names must be the verb the skew guard exempts"
);
assert_eq!(recovery_verb(&Commands::Daemon(daemon_args(None))), None);
assert_eq!(
VersionGuard::for_command(&Commands::Daemon(daemon_args(None))),
VersionGuard::Enforce
);
assert_eq!(recovery_verb(&Commands::Flock(flock_args())), None);
assert_eq!(
VersionGuard::for_command(&Commands::Flock(flock_args())),
VersionGuard::Warn
);
assert_eq!(
VersionGuard::for_command(&Commands::Kill),
VersionGuard::Exempt
);
assert_eq!(
VersionGuard::for_command(&Commands::Add(add_args())),
VersionGuard::Enforce
);
}
#[test]
fn every_read_verb_is_one_of_the_documented_read_verbs() {
for (argv, name) in [
(&["flock"][..], "flock"),
(&["describe", "web"], "describe"),
(&["bleats", "web"], "bleats"),
(&["bleats", "web", "--no-follow"], "bleats"),
] {
let command = verb(argv);
let found = read_verb(&command).unwrap_or_else(|| panic!("{command:?} must stay a read"));
assert_eq!(found, name);
assert!(
READ_VERBS.contains(&found),
"{found} warns but is undocumented"
);
assert_eq!(VersionGuard::for_command(&command), VersionGuard::Warn);
}
assert_eq!(
read_verb(&Commands::Kill),
None,
"a recovery verb is not a read verb"
);
}
#[test]
fn every_verb_that_changes_the_flock_still_enforces() {
for argv in [
&["start", "web"][..],
&["add", "web"],
&["stop", "web"],
&["restart", "web"],
&["reload", "web"],
&["delete", "web"],
&["stock", "web", "2"],
&["enable", "web"],
&["disable", "web"],
&["trigger", "web", "go"],
&["signal", "web", "TERM"],
&["whisper", "web", "hi"],
&["reopen", "web"],
&["flush", "web"],
&["save"],
&["muster"],
&["copy", "web", "web2"],
&["kv", "set", "key", "value"],
&["set", "key", "value"],
] {
let command = verb(argv);
assert_eq!(
VersionGuard::for_command(&command),
VersionGuard::Enforce,
"{argv:?}"
);
}
}