test: trim redundant test coverage

This commit is contained in:
wonfen
2026-08-19 10:24:37 +08:00
parent 807f9a206d
commit e15ddab542
38 changed files with 194 additions and 4259 deletions
-148
View File
@@ -298,151 +298,3 @@ impl NotificationSystem {
}
}
}
#[cfg(test)]
mod tests {
use super::{FailedOperation, FailureTable};
fn table() -> FailureTable {
FailureTable::default()
}
#[test]
fn reading_does_not_clear() {
let table = table();
table.record(
FailedOperation::SystemProxyRestore,
"SYSPROXY_PRIVILEGE_REQUIRED",
"refused".into(),
);
assert_eq!(table.snapshot(), table.snapshot());
assert_eq!(table.snapshot().len(), 1);
}
#[test]
fn a_code_keeps_only_its_most_recent_failure() {
let table = table();
table.record(
FailedOperation::SystemProxyRestore,
"SYSPROXY_PRIVILEGE_REQUIRED",
"first".into(),
);
table.record(
FailedOperation::SystemProxyRestore,
"SYSPROXY_PRIVILEGE_REQUIRED",
"second".into(),
);
let failures = table.snapshot();
assert_eq!(failures.len(), 1);
assert_eq!(failures[0].detail, "second");
}
#[test]
fn a_new_failure_under_a_known_code_gets_a_new_sequence() {
let table = table();
table.record(
FailedOperation::SystemProxyRestore,
"SYSPROXY_DIRECT_FALLBACK",
"a".into(),
);
let first = table.snapshot()[0].sequence;
table.record(
FailedOperation::SystemProxyRestore,
"SYSPROXY_DIRECT_FALLBACK",
"b".into(),
);
assert!(table.snapshot()[0].sequence > first);
}
#[test]
fn failures_are_reported_oldest_first() {
let table = table();
table.record(FailedOperation::SystemProxyRestore, "FIRST", "a".into());
table.record(FailedOperation::SystemProxyRestore, "SECOND", "b".into());
let failures = table.snapshot();
let codes: Vec<&str> = failures.iter().map(|failure| failure.code.as_str()).collect();
assert_eq!(codes, ["FIRST", "SECOND"]);
}
#[test]
fn a_working_proxy_retires_what_it_disproves() {
let table = table();
table.record(
FailedOperation::SystemProxyRestore,
"SYSPROXY_PRIVILEGE_REQUIRED",
"refused".into(),
);
assert!(table.retire_system_proxy(false));
assert!(table.snapshot().is_empty());
}
#[test]
fn a_users_request_is_retired_only_by_reaching_the_state_they_asked_for() {
let table = table();
table.record(
FailedOperation::SystemProxyDisable,
"SYSPROXY_PRIVILEGE_REQUIRED",
"refused".into(),
);
assert!(!table.retire_system_proxy(true));
assert_eq!(table.snapshot().len(), 1);
assert!(table.retire_system_proxy(false));
assert!(table.snapshot().is_empty());
}
#[test]
fn a_failed_enable_is_retired_by_the_proxy_coming_on() {
let table = table();
table.record(
FailedOperation::SystemProxyEnable,
"SYSPROXY_DIRECT_FALLBACK",
"fell back".into(),
);
assert!(!table.retire_system_proxy(false));
assert!(table.retire_system_proxy(true));
assert!(table.snapshot().is_empty());
}
#[test]
fn a_stopped_guard_is_retired_by_a_guard_starting_again_and_not_by_an_apply() {
let table = table();
table.record(
FailedOperation::SystemProxyGuard,
"SYSPROXY_GUARD_STOPPED",
"gave up".into(),
);
assert!(!table.retire_system_proxy(true));
assert!(!table.retire_system_proxy(false));
assert_eq!(table.snapshot().len(), 1);
assert!(table.retire_guard());
assert!(table.snapshot().is_empty());
}
#[test]
fn retiring_a_guard_leaves_everything_else_alone() {
let table = table();
table.record(
FailedOperation::SystemProxyEnable,
"SYSPROXY_PRIVILEGE_REQUIRED",
"refused".into(),
);
assert!(!table.retire_guard());
assert_eq!(table.snapshot().len(), 1);
}
#[test]
fn retiring_nothing_reports_nothing() {
assert!(!table().retire_system_proxy(true));
}
}