use super::{CacheWarning, CacheWarningReason};
#[test]
fn load_failure_reasons_render_exact_json() {
let cases = [
(CacheWarningReason::Missing, "missing"),
(CacheWarningReason::CacheRootUnavailable, "cache-root-unavailable"),
(CacheWarningReason::Unreadable, "unreadable"),
(CacheWarningReason::SourceMismatch, "source-mismatch"),
(CacheWarningReason::Incompatible, "incompatible"),
(CacheWarningReason::Invalid, "invalid"),
];
for (reason, token) in cases {
let warning = CacheWarning::compile_from_text(reason);
assert_eq!(
warning.to_string(),
format!(
"{{\"type\":\"forbidden-strings/cache-warning\",\"schemaVersion\":1,\"reason\":\"{token}\",\"recovery\":\"compile-from-text\"}}",
),
);
}
}
#[test]
fn write_failure_renders_exact_json() {
assert_eq!(
CacheWarning::write_failed().to_string(),
"{\"type\":\"forbidden-strings/cache-warning\",\"schemaVersion\":1,\"reason\":\"write-failed\",\"recovery\":\"continue-with-compiled-rules\"}",
);
}