use std::io::{Error as IoError, ErrorKind};
use sqry_nl::NlError;
fn forced_serde_error() -> serde_json::Error {
serde_json::from_str::<serde_json::Value>("{not valid json").unwrap_err()
}
#[test]
fn all_variants_constructable() {
let variants: Vec<NlError> = vec![
NlError::ModelDirNotFound("/nonexistent/path".to_string()),
NlError::ChecksumMismatch {
file: "intent_classifier.onnx".to_string(),
expected: "abc".to_string(),
actual: "def".to_string(),
},
NlError::ChecksumsMissing,
NlError::ChecksummedFileMissing("tokenizer.json".to_string()),
NlError::OnnxRuntimeMissing {
hint: "install libonnxruntime".to_string(),
},
NlError::ManifestSha256Mismatch {
file: "sqry-models-v1.0.0.tar.gz".to_string(),
expected: "abc".to_string(),
actual: "def".to_string(),
},
NlError::from(forced_serde_error()),
NlError::DownloadDisabled,
NlError::DownloadFailed("connection refused".to_string()),
];
for err in &variants {
let display = err.to_string();
assert!(
!display.is_empty(),
"Display impl produced empty string for {err:?}"
);
let debug = format!("{err:?}");
assert!(
!debug.is_empty(),
"Debug impl produced empty string for variant rendered as {display}"
);
}
let io_err: NlError = IoError::new(ErrorKind::NotFound, "missing").into();
assert!(matches!(io_err, NlError::Io(_)));
}