diff --git a/Cargo.lock b/Cargo.lock index 0a1d9aad18..98e333b6cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -202,6 +202,7 @@ dependencies = [ "argon2", "basen", "bcrypt", + "cfg-if", "chrono", "cuid2", "emojis", diff --git a/Cargo.toml b/Cargo.toml index 74d032aeae..3ada688b7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ napi-build = "2.1.3" argon2 = "0.5.3" basen = "0.1.0" bcrypt = "0.15.1" +cfg-if = "1.0.0" chrono = "0.4.38" convert_case = "0.6.0" cuid2 = "0.1.2" diff --git a/packages/backend-rs/Cargo.toml b/packages/backend-rs/Cargo.toml index c1b511b992..eb0fa82631 100644 --- a/packages/backend-rs/Cargo.toml +++ b/packages/backend-rs/Cargo.toml @@ -7,6 +7,7 @@ rust-version = "1.74" [features] default = [] napi = ["dep:napi", "dep:napi-derive"] +ci = [] [lib] crate-type = ["cdylib", "lib"] @@ -46,6 +47,7 @@ url = { workspace = true } urlencoding = { workspace = true } [dev-dependencies] +cfg-if = { workspace = true } pretty_assertions = { workspace = true } [build-dependencies] diff --git a/packages/backend-rs/src/misc/get_image_size.rs b/packages/backend-rs/src/misc/get_image_size.rs index ac0de89015..c74b70e603 100644 --- a/packages/backend-rs/src/misc/get_image_size.rs +++ b/packages/backend-rs/src/misc/get_image_size.rs @@ -123,17 +123,20 @@ 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 - // (should be disabled in CI tasks) - cache::delete_one(cache::Category::FetchUrl, png_url_1).unwrap(); - cache::delete_one(cache::Category::FetchUrl, png_url_2).unwrap(); - cache::delete_one(cache::Category::FetchUrl, png_url_3).unwrap(); - cache::delete_one(cache::Category::FetchUrl, rotated_jpeg_url).unwrap(); - cache::delete_one(cache::Category::FetchUrl, webp_url_1).unwrap(); - cache::delete_one(cache::Category::FetchUrl, webp_url_2).unwrap(); - cache::delete_one(cache::Category::FetchUrl, ico_url).unwrap(); - cache::delete_one(cache::Category::FetchUrl, gif_url).unwrap(); - cache::delete_one(cache::Category::FetchUrl, mp3_url).unwrap(); + cfg_if::cfg_if! { + if #[cfg(not(feature = "ci"))] { + // Delete caches in case you run this test multiple times + cache::delete_one(cache::Category::FetchUrl, png_url_1).unwrap(); + cache::delete_one(cache::Category::FetchUrl, png_url_2).unwrap(); + cache::delete_one(cache::Category::FetchUrl, png_url_3).unwrap(); + cache::delete_one(cache::Category::FetchUrl, rotated_jpeg_url).unwrap(); + cache::delete_one(cache::Category::FetchUrl, webp_url_1).unwrap(); + cache::delete_one(cache::Category::FetchUrl, webp_url_2).unwrap(); + cache::delete_one(cache::Category::FetchUrl, ico_url).unwrap(); + cache::delete_one(cache::Category::FetchUrl, gif_url).unwrap(); + cache::delete_one(cache::Category::FetchUrl, mp3_url).unwrap(); + } + } let png_size_1 = ImageSize { width: 1024, diff --git a/packages/backend-rs/src/misc/latest_version.rs b/packages/backend-rs/src/misc/latest_version.rs index 1994d3a921..5620d204d1 100644 --- a/packages/backend-rs/src/misc/latest_version.rs +++ b/packages/backend-rs/src/misc/latest_version.rs @@ -79,8 +79,11 @@ mod unit_test { #[tokio::test] async fn check_version() { - // TODO: don't need to do this in CI tasks - cache::delete_one(cache::Category::FetchUrl, UPSTREAM_PACKAGE_JSON_URL).unwrap(); + cfg_if::cfg_if! { + if #[cfg(not(feature = "ci"))] { + cache::delete_one(cache::Category::FetchUrl, UPSTREAM_PACKAGE_JSON_URL).unwrap(); + } + } // fetch from firefish.dev validate_version(latest_version().await.unwrap());