use crate::utils::config_reload_reason::is_transient_read_race;
const DUPLICATE_FIELD: &str = "Failed to parse config file: \"/home/u/.opencrabs/config.toml\": \
TOML parse error at line 1, column 1\n |\n1 | [providers]\n | ^\nduplicate field `a2a`";
#[test]
fn a_duplicate_field_is_never_a_write_race() {
assert!(
!is_transient_read_race(DUPLICATE_FIELD, false),
"a real content error must not be described as transient"
);
}
#[test]
fn a_duplicate_field_stays_real_even_if_the_file_reads_empty_now() {
assert!(!is_transient_read_race(DUPLICATE_FIELD, true));
}
#[test]
fn other_content_errors_are_real_too() {
for reason in [
"unknown field `porrt`, expected one of ...",
"invalid type: string, expected a boolean",
"missing field `token`",
"invalid value: integer `-1`",
] {
assert!(
!is_transient_read_race(reason, false),
"{reason} needs a human, not a retry"
);
}
}
#[test]
fn an_empty_file_is_a_write_race() {
assert!(is_transient_read_race(
"TOML parse error at line 1, column 1",
true
));
}
#[test]
fn an_eof_error_is_a_write_race_without_needing_the_file_check() {
assert!(is_transient_read_race("unexpected eof encountered", false));
}
#[test]
fn an_unrecognised_error_is_treated_as_real() {
assert!(!is_transient_read_race(
"something nobody has seen before",
false
));
}
#[test]
fn line_one_column_one_alone_no_longer_implies_transient() {
assert!(!is_transient_read_race(
"TOML parse error at line 1, column 1\nduplicate field `a2a`",
false
));
}