mirror of
https://github.com/perstarkse/minne.git
synced 2026-07-04 12:01:48 +02:00
clippy: adhere to pedantic clippy, uniform test error handling
This commit is contained in:
@@ -155,21 +155,20 @@ mod tests {
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn extracts_text_using_memory_storage_backend() {
|
||||
let mut config = AppConfig::default();
|
||||
config.storage = StorageKind::Memory;
|
||||
async fn extracts_text_using_memory_storage_backend() -> anyhow::Result<()> {
|
||||
let config = AppConfig {
|
||||
storage: StorageKind::Memory,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let storage = StorageManager::new(&config)
|
||||
.await
|
||||
.expect("create storage manager");
|
||||
let storage = StorageManager::new(&config).await?;
|
||||
|
||||
let location = "user/test/file.txt";
|
||||
let contents = b"hello from memory storage";
|
||||
|
||||
storage
|
||||
.put(location, Bytes::from(contents.as_slice().to_vec()))
|
||||
.await
|
||||
.expect("write object");
|
||||
.await?;
|
||||
|
||||
let now = Utc::now();
|
||||
let file_info = FileInfo {
|
||||
@@ -185,16 +184,14 @@ mod tests {
|
||||
|
||||
let namespace = "test_ns";
|
||||
let database = &Uuid::new_v4().to_string();
|
||||
let db = SurrealDbClient::memory(namespace, database)
|
||||
.await
|
||||
.expect("create surreal memory");
|
||||
let db = SurrealDbClient::memory(namespace, database).await?;
|
||||
|
||||
let openai_client = Client::with_config(OpenAIConfig::default());
|
||||
|
||||
let text = extract_text_from_file(&file_info, &db, &openai_client, &config, &storage)
|
||||
.await
|
||||
.expect("extract text");
|
||||
.await?;
|
||||
|
||||
assert_eq!(text, String::from_utf8_lossy(contents));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -715,6 +715,7 @@ const fn prompt_for_attempt(attempt: usize, base_prompt: &str) -> &str {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use anyhow::{self};
|
||||
|
||||
#[test]
|
||||
fn test_looks_good_enough_short_text() {
|
||||
@@ -737,15 +738,16 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_debug_dump_directory_env_var() {
|
||||
fn test_debug_dump_directory_env_var() -> anyhow::Result<()> {
|
||||
std::env::remove_var(DEBUG_IMAGE_ENV_VAR);
|
||||
assert!(debug_dump_directory().is_none());
|
||||
|
||||
std::env::set_var(DEBUG_IMAGE_ENV_VAR, "/tmp/minne_pdf_debug");
|
||||
let dir = debug_dump_directory().expect("expected debug directory");
|
||||
let dir = debug_dump_directory().ok_or_else(|| anyhow::anyhow!("expected debug directory"))?;
|
||||
assert_eq!(dir, PathBuf::from("/tmp/minne_pdf_debug"));
|
||||
|
||||
std::env::remove_var(DEBUG_IMAGE_ENV_VAR);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -142,29 +142,34 @@ fn ensure_ingestion_url_allowed(url: &url::Url) -> Result<String, AppError> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use anyhow::{self};
|
||||
|
||||
#[test]
|
||||
fn rejects_unsupported_scheme() {
|
||||
let url = url::Url::parse("ftp://example.com").expect("url");
|
||||
fn rejects_unsupported_scheme() -> anyhow::Result<()> {
|
||||
let url = url::Url::parse("ftp://example.com")?;
|
||||
assert!(ensure_ingestion_url_allowed(&url).is_err());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_localhost() {
|
||||
let url = url::Url::parse("http://localhost/resource").expect("url");
|
||||
fn rejects_localhost() -> anyhow::Result<()> {
|
||||
let url = url::Url::parse("http://localhost/resource")?;
|
||||
assert!(ensure_ingestion_url_allowed(&url).is_err());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_private_ipv4() {
|
||||
let url = url::Url::parse("http://192.168.1.10/index.html").expect("url");
|
||||
fn rejects_private_ipv4() -> anyhow::Result<()> {
|
||||
let url = url::Url::parse("http://192.168.1.10/index.html")?;
|
||||
assert!(ensure_ingestion_url_allowed(&url).is_err());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn allows_public_domain_and_sanitizes() {
|
||||
let url = url::Url::parse("https://sub.example.com/path").expect("url");
|
||||
let sanitized = ensure_ingestion_url_allowed(&url).expect("allowed");
|
||||
fn allows_public_domain_and_sanitizes() -> anyhow::Result<()> {
|
||||
let url = url::Url::parse("https://sub.example.com/path")?;
|
||||
let sanitized = ensure_ingestion_url_allowed(&url)?;
|
||||
assert_eq!(sanitized, "sub_example_com");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user