use super::client::{CanonClient, CanonError};
use super::types::{
CanonEntry, CanonMatchRequest, CanonMatchResponse, RequestVerifyBody, RequestVerifyResponse,
};
#[derive(Debug, Default, Clone, Copy)]
pub struct NoopCanonClient;
impl CanonClient for NoopCanonClient {
fn match_annotations(
&self,
_req: &CanonMatchRequest,
) -> Result<CanonMatchResponse, CanonError> {
Err(CanonError::NotEnabled)
}
fn get_entry(&self, _canon_id: &str, _version: Option<&str>) -> Result<CanonEntry, CanonError> {
Err(CanonError::NotEnabled)
}
fn request_verify(
&self,
_body: &RequestVerifyBody,
) -> Result<RequestVerifyResponse, CanonError> {
Err(CanonError::NotEnabled)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::canon::types::AnnotationMatchInput;
#[test]
fn match_annotations_returns_not_enabled() {
let client = NoopCanonClient;
let req = CanonMatchRequest {
annotations: vec![AnnotationMatchInput {
annotation_text: "test".into(),
applies_to: vec!["fn".into()],
}],
confidence_threshold: 0.85,
};
let err = client.match_annotations(&req).unwrap_err();
assert!(matches!(err, CanonError::NotEnabled));
}
#[test]
fn get_entry_returns_not_enabled() {
let client = NoopCanonClient;
let err = client.get_entry("any_id", None).unwrap_err();
assert!(matches!(err, CanonError::NotEnabled));
}
#[test]
fn request_verify_returns_not_enabled() {
let client = NoopCanonClient;
let err = client
.request_verify(&RequestVerifyBody {
canon_id: "any".into(),
notes: None,
})
.unwrap_err();
assert!(matches!(err, CanonError::NotEnabled));
}
#[test]
fn noop_client_is_object_safe() {
let _boxed: Box<dyn CanonClient> = Box::new(NoopCanonClient);
}
}