} } Err(anyhow!("unknown content type: {s}")) } } #[cfg(test)] mod tests { use super::*; #[test] fn for_extension() { assert_eq!( Media::content_type_for_path(Path::new("pepe.jpg")).unwrap(), ("image/jpeg", BrotliEncoderMode::BROTLI_MODE_GENERIC) ); assert_eq!( Media::content_type_for_path(Path::new("pepe.jpeg")).unwrap(), ("image/jpeg", BrotliEncoderMode::BROTLI_MODE_GENERIC) ); assert_eq!( Media::content_type_for_path(Path::new("pepe.JPG")).unwrap(), ("image/jpeg", BrotliEncoderMode::BROTLI_MODE_GENERIC) ); assert_eq!( Media::content_type_for_path(Path::new("pepe.txt")).unwrap(), ( "text/plain;charset=utf-8", BrotliEncoderMode::BROTLI_MODE_TEXT ) ); assert_regex_match!( Media::content_type_for_path(Path::new("pepe.foo")).unwrap_err(), r"unsupported file extension `\.foo`, supported extensions: apng .*" ); } #[test] fn h264_in_mp4_is_allowed() { assert!(Media::check_mp4_codec(Path::new("examples/h264.mp4")).is_ok(),);