use super::traits::{ParityCapabilities, ParityHandler, RepairResult, VerifyResult};
use async_trait::async_trait;
use std::path::Path;
pub struct NoOpParityHandler;
#[async_trait]
impl ParityHandler for NoOpParityHandler {
async fn verify(&self, _par2_file: &Path) -> crate::Result<VerifyResult> {
Err(crate::Error::NotSupported(
"PAR2 verification requires external par2 binary. \
Configure par2_path in config or ensure par2 is in PATH."
.into(),
))
}
async fn repair(&self, _par2_file: &Path) -> crate::Result<RepairResult> {
Err(crate::Error::NotSupported(
"PAR2 repair requires external par2 binary. \
Configure par2_path in config or ensure par2 is in PATH."
.into(),
))
}
fn capabilities(&self) -> ParityCapabilities {
ParityCapabilities {
can_verify: false,
can_repair: false,
}
}
fn name(&self) -> &'static str {
"noop"
}
}
#[allow(clippy::unwrap_used, clippy::expect_used)]
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_verify_returns_not_supported() {
let handler = NoOpParityHandler;
let result = handler.verify(Path::new("test.par2")).await;
assert!(result.is_err());
assert!(matches!(result, Err(crate::Error::NotSupported(_))));
}
#[tokio::test]
async fn test_repair_returns_not_supported() {
let handler = NoOpParityHandler;
let result = handler.repair(Path::new("test.par2")).await;
assert!(result.is_err());
match result {
Err(crate::Error::NotSupported(msg)) => {
assert!(msg.contains("par2 binary"));
}
_ => panic!("Expected NotSupported error"),
}
}
#[tokio::test]
async fn test_repair_error_message_content() {
let handler = NoOpParityHandler;
let result = handler.repair(Path::new("test.par2")).await;
match result {
Err(crate::Error::NotSupported(msg)) => {
assert!(
msg.contains("PAR2 repair"),
"Error message should mention PAR2 repair"
);
assert!(
msg.contains("external par2 binary"),
"Error message should mention external binary requirement"
);
assert!(
msg.contains("par2_path") || msg.contains("PATH"),
"Error message should mention configuration or PATH"
);
}
_ => panic!("Expected NotSupported error"),
}
}
#[tokio::test]
async fn test_repair_error_is_not_supported_variant() {
let handler = NoOpParityHandler;
let result = handler.repair(Path::new("test.par2")).await;
assert!(matches!(result, Err(crate::Error::NotSupported(_))));
}
}