use actix_files::NamedFile;
use std::error::Error;
use std::path::PathBuf;
pub(crate) async fn get_favicon() -> Result<NamedFile, Box<dyn Error>> {
let path: PathBuf = "static/favicon.ico".into();
Ok(NamedFile::open(path)?)
}
#[cfg(test)]
mod tests {
use super::*;
use std::fs;
use std::path::PathBuf;
#[tokio::test]
async fn test_get_favicon_not_found() {
let original = PathBuf::from("static/favicon.ico");
let temp = PathBuf::from("static/favicon_temp.ico");
fs::rename(&original, &temp).expect("Failed to rename favicon.ico for the test");
let result = get_favicon().await;
assert!(
result.is_err(),
"get_favicon should return an Err when the file is missing"
);
fs::rename(&temp, &original).expect("Failed to restore favicon.ico after the test");
}
}