Update test cases

This commit is contained in:
Harrison Burt 2022-03-30 21:55:42 +01:00
parent 0ba671be56
commit eb2d621c4c
4 changed files with 29 additions and 8 deletions

View File

@ -415,6 +415,3 @@ const fn default_original_format() -> ImageKind {
ImageKind::Png
}
fn default_preset() -> String {
String::from("original")
}

View File

@ -1,8 +1,9 @@
use std::sync::Arc;
use image::load_from_memory_with_format;
use poem::Route;
use poem::http::StatusCode;
use poem_openapi::OpenApiService;
use poem::test::TestClient;
use poem::test::{TestClient, TestResponse};
use poem::web::headers;
use tokio::sync::Semaphore;
@ -62,11 +63,24 @@ async fn setup_environment(cfg: &str) -> anyhow::Result<TestClient<Route>> {
}
async fn validate_image_content(
res: TestResponse,
expected_format: image::ImageFormat,
) -> anyhow::Result<()> {
let body = res.0.into_body().into_bytes().await?;
load_from_memory_with_format(&body, expected_format)
.expect("Invalid image returned for expected format");
Ok(())
}
#[tokio::test]
async fn test_basic_aot_upload_retrieval_without_guessing() -> anyhow::Result<()> {
let app = setup_environment(AOT_CONFIG).await?;
let res = app.post("/v1/user-profiles")
let res = app.post("/v1/images/user-profiles")
.body(TEST_IMAGE)
.content_type("application/octet-stream".to_string())
.typed_header(headers::ContentLength(TEST_IMAGE.len() as u64))
@ -90,6 +104,8 @@ async fn test_basic_aot_upload_retrieval_without_guessing() -> anyhow::Result<()
res.assert_status(StatusCode::OK);
res.assert_content_type(&"image/webp".to_string());
validate_image_content(res, image::ImageFormat::WebP).await?;
Ok(())
}
@ -97,7 +113,7 @@ async fn test_basic_aot_upload_retrieval_without_guessing() -> anyhow::Result<()
async fn test_basic_aot_upload_retrieval_with_guessing() -> anyhow::Result<()> {
let app = setup_environment(AOT_CONFIG).await?;
let res = app.post("/v1/user-profiles")
let res = app.post("/v1/images/user-profiles")
.body(TEST_IMAGE)
.content_type("application/octet-stream".to_string())
.typed_header(headers::ContentLength(TEST_IMAGE.len() as u64))
@ -121,6 +137,8 @@ async fn test_basic_aot_upload_retrieval_with_guessing() -> anyhow::Result<()> {
res.assert_status(StatusCode::OK);
res.assert_content_type(&"image/webp".to_string());
validate_image_content(res, image::ImageFormat::WebP).await?;
Ok(())
}
@ -152,6 +170,8 @@ async fn test_basic_jit_upload_retrieval() -> anyhow::Result<()> {
res.assert_status(StatusCode::OK);
res.assert_content_type(&"image/jpeg".to_string());
validate_image_content(res, image::ImageFormat::Jpeg).await?;
Ok(())
}
@ -184,6 +204,8 @@ async fn test_jit_upload_custom_format_retrieval() -> anyhow::Result<()> {
res.assert_status(StatusCode::OK);
res.assert_content_type(&"image/png".to_string());
validate_image_content(res, image::ImageFormat::Png).await?;
Ok(())
}
@ -215,6 +237,8 @@ async fn test_basic_realtime_upload_retrieval() -> anyhow::Result<()> {
res.assert_status(StatusCode::OK);
res.assert_content_type(&"image/png".to_string());
validate_image_content(res, image::ImageFormat::Png).await?;
Ok(())
}
@ -248,6 +272,8 @@ async fn test_realtime_resizing() -> anyhow::Result<()> {
res.assert_status(StatusCode::OK);
res.assert_content_type(&"image/png".to_string());
validate_image_content(res, image::ImageFormat::Png).await?;
Ok(())
}

View File

@ -2,7 +2,6 @@ backend:
filesystem: # Use the filesystem backend.
directory: "data"
base_serving_path: "/images" # Serve buckets out of `/images`
global_cache:
max_images: 1000 # At most cache 1000 images.
max_capacity: 500 # 500MB max capacity.

View File

@ -2,7 +2,6 @@ backend:
filesystem: # Use the filesystem backend.
directory: "data"
base_serving_path: "/images" # Serve buckets out of `/images`
global_cache:
max_images: 1000 # At most cache 1000 images.
max_capacity: 500 # 500MB max capacity.