test (backend-rs): add tests

This commit is contained in:
naskya 2024-05-04 22:59:49 +09:00
parent 38c0de39b9
commit 4992999bb7
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
2 changed files with 19 additions and 3 deletions

View file

@ -123,8 +123,7 @@ mod unit_test {
let gif_url = "https://firefish.dev/firefish/firefish/-/raw/b9c3dfbd3d473cb2cee20c467eeae780bc401271/packages/backend/test/resources/anime.gif";
let mp3_url = "https://firefish.dev/firefish/firefish/-/blob/5891a90f71a8b9d5ea99c683ade7e485c685d642/packages/backend/assets/sounds/aisha/1.mp3";
// Delete caches in case you run this test multiple times
#[cfg(not(feature = "ci"))]
// delete caches in case you run this test multiple times
cache::delete_all(cache::Category::FetchUrl).unwrap();
let png_size_1 = ImageSize {
@ -188,4 +187,15 @@ mod unit_test {
assert_eq!(gif_size, get_image_size_from_url(gif_url).await.unwrap());
assert!(get_image_size_from_url(mp3_url).await.is_err());
}
#[tokio::test]
async fn too_many_attempts() {
let url = "https://firefish.dev/firefish/firefish/-/raw/5891a90f71a8b9d5ea99c683ade7e485c685d642/packages/backend/assets/splash.png";
// delete caches in case you run this test multiple times
cache::delete_one(cache::Category::FetchUrl, url).unwrap();
assert!(get_image_size_from_url(url).await.is_ok());
assert!(get_image_size_from_url(url).await.is_err());
}
}

View file

@ -75,11 +75,17 @@ mod unit_test {
// DD
assert!(&version[6..8] >= "01");
assert!(&version[6..8] <= "31");
// -X
if version.len() > 8 {
assert!(version.chars().nth(8).unwrap() == '-');
assert!(version[9..].chars().all(|c| c.is_ascii_digit()));
}
}
#[tokio::test]
async fn check_version() {
#[cfg(not(feature = "ci"))]
// delete caches in case you run this test multiple times
cache::delete_one(cache::Category::FetchUrl, UPSTREAM_PACKAGE_JSON_URL).unwrap();
// fetch from firefish.dev