chore (backend-rs): change test names

This commit is contained in:
naskya 2024-06-10 18:09:08 +09:00
parent 581668c306
commit bc7fdc5c0b
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
18 changed files with 134 additions and 114 deletions

View file

@ -51,13 +51,7 @@ mod unit_test {
#[tokio::test]
async fn connect_concurrent() {
let [c1, c2, c3, c4, c5] = [
get_conn(),
get_conn(),
get_conn(),
get_conn(),
get_conn(),
];
let [c1, c2, c3, c4, c5] = [get_conn(), get_conn(), get_conn(), get_conn(), get_conn()];
let _ = tokio::try_join!(c1, c2, c3, c4, c5).unwrap();
}

View file

@ -129,13 +129,7 @@ mod unit_test {
#[tokio::test]
async fn connect_concurrent() {
let [c1, c2, c3, c4, c5] = [
get_conn(),
get_conn(),
get_conn(),
get_conn(),
get_conn(),
];
let [c1, c2, c3, c4, c5] = [get_conn(), get_conn(), get_conn(), get_conn(), get_conn()];
let _ = tokio::try_join!(c1, c2, c3, c4, c5).unwrap();
}

View file

@ -64,7 +64,7 @@ mod unit_test {
use std::str::FromStr;
#[test]
fn test_acct_to_string() {
fn acct_to_string() {
let remote_acct = Acct {
username: "firefish".to_string(),
host: Some("example.com".to_string()),
@ -81,7 +81,7 @@ mod unit_test {
}
#[test]
fn test_string_to_acct() {
fn string_to_acct() {
let remote_acct = Acct {
username: "firefish".to_string(),
host: Some("example.com".to_string()),

View file

@ -100,11 +100,11 @@ pub async fn fetch_nodeinfo(host: &str) -> Result<Nodeinfo, Error> {
#[cfg(test)]
mod unit_test {
use super::{check_nodeinfo_link, fetch_nodeinfo, NodeinfoLink, NodeinfoLinks};
use super::{NodeinfoLink, NodeinfoLinks};
use pretty_assertions::assert_eq;
#[test]
fn test_check_nodeinfo_link() {
fn check_nodeinfo_link() {
let links_1 = NodeinfoLinks {
links: vec![
NodeinfoLink {
@ -118,7 +118,7 @@ mod unit_test {
],
};
assert_eq!(
check_nodeinfo_link(links_1).unwrap(),
super::check_nodeinfo_link(links_1).unwrap(),
"https://example.com/real"
);
@ -135,7 +135,7 @@ mod unit_test {
],
};
assert_eq!(
check_nodeinfo_link(links_2).unwrap(),
super::check_nodeinfo_link(links_2).unwrap(),
"https://example.com/real"
);
@ -151,13 +151,13 @@ mod unit_test {
},
],
};
check_nodeinfo_link(links_3).expect_err("No nodeinfo");
super::check_nodeinfo_link(links_3).expect_err("No nodeinfo");
}
#[tokio::test]
async fn test_fetch_nodeinfo() {
async fn fetch_nodeinfo() {
assert_eq!(
fetch_nodeinfo("info.firefish.dev")
super::fetch_nodeinfo("info.firefish.dev")
.await
.unwrap()
.software

View file

@ -71,7 +71,7 @@ mod unit_test {
use super::check_word_mute_impl;
#[test]
fn test_word_mute_match() {
fn word_mute_match() {
let texts = vec![
"The quick brown fox jumps over the lazy dog.".to_string(),
"色は匂へど 散りぬるを 我が世誰ぞ 常ならむ".to_string(),

View file

@ -14,25 +14,24 @@ pub fn safe_for_sql(src: &str) -> bool {
#[cfg(test)]
mod unit_test {
use super::{safe_for_sql, sql_like_escape};
use pretty_assertions::assert_eq;
#[test]
fn sql_like_escape_test() {
assert_eq!(sql_like_escape(""), "");
assert_eq!(sql_like_escape("abc"), "abc");
assert_eq!(sql_like_escape("a%bc"), r"a\%bc");
assert_eq!(sql_like_escape("a呼%吸bc"), r"a呼\%吸bc");
assert_eq!(sql_like_escape("a呼%吸b%_c"), r"a呼\%吸b\%\_c");
assert_eq!(sql_like_escape("_اللغة العربية"), r"\_اللغة العربية");
fn sql_like_escape() {
assert_eq!(super::sql_like_escape(""), "");
assert_eq!(super::sql_like_escape("abc"), "abc");
assert_eq!(super::sql_like_escape("a%bc"), r"a\%bc");
assert_eq!(super::sql_like_escape("a呼%吸bc"), r"a呼\%吸bc");
assert_eq!(super::sql_like_escape("a呼%吸b%_c"), r"a呼\%吸b\%\_c");
assert_eq!(super::sql_like_escape("_اللغة العربية"), r"\_اللغة العربية");
}
#[test]
fn safe_for_sql_test() {
assert!(safe_for_sql("123"));
assert!(safe_for_sql("人間"));
assert!(!safe_for_sql("人間\x09"));
assert!(!safe_for_sql("abc\ndef"));
assert!(!safe_for_sql("%something%"));
fn safe_for_sql() {
assert!(super::safe_for_sql("123"));
assert!(super::safe_for_sql("人間"));
assert!(!super::safe_for_sql("人間\x09"));
assert!(!super::safe_for_sql("abc\ndef"));
assert!(!super::safe_for_sql("%something%"));
}
}

View file

@ -30,16 +30,21 @@ pub fn format_milliseconds(milliseconds: u32) -> String {
#[cfg(test)]
mod unit_test {
use super::format_milliseconds;
use pretty_assertions::assert_eq;
#[test]
fn format_milliseconds_test() {
assert_eq!(format_milliseconds(1000), "1 second(s)");
assert_eq!(format_milliseconds(1387938), "23 minute(s), 7 second(s)");
assert_eq!(format_milliseconds(34200457), "9 hour(s), 30 minute(s)");
fn format_milliseconds() {
assert_eq!(super::format_milliseconds(1000), "1 second(s)");
assert_eq!(
format_milliseconds(998244353),
super::format_milliseconds(1387938),
"23 minute(s), 7 second(s)"
);
assert_eq!(
super::format_milliseconds(34200457),
"9 hour(s), 30 minute(s)"
);
assert_eq!(
super::format_milliseconds(998244353),
"11 day(s), 13 hour(s), 17 minute(s), 24 second(s)"
);
}

View file

@ -122,12 +122,12 @@ pub async fn get_image_size_from_url(url: &str) -> Result<ImageSize, Error> {
#[cfg(test)]
mod unit_test {
use super::{get_image_size_from_url, ImageSize};
use super::ImageSize;
use crate::database::cache;
use pretty_assertions::assert_eq;
#[tokio::test]
async fn test_get_image_size() {
async fn get_image_size_from_url() {
let png_url_1 = "https://firefish.dev/firefish/firefish/-/raw/5891a90f71a8b9d5ea99c683ade7e485c685d642/packages/backend/assets/splash.png";
let png_url_2 = "https://firefish.dev/firefish/firefish/-/raw/5891a90f71a8b9d5ea99c683ade7e485c685d642/packages/backend/assets/notification-badges/at.png";
let png_url_3 = "https://firefish.dev/firefish/firefish/-/raw/5891a90f71a8b9d5ea99c683ade7e485c685d642/packages/backend/assets/api-doc.png";
@ -176,31 +176,39 @@ mod unit_test {
assert_eq!(
png_size_1,
get_image_size_from_url(png_url_1).await.unwrap()
super::get_image_size_from_url(png_url_1).await.unwrap()
);
assert_eq!(
png_size_2,
get_image_size_from_url(png_url_2).await.unwrap()
super::get_image_size_from_url(png_url_2).await.unwrap()
);
assert_eq!(
png_size_3,
get_image_size_from_url(png_url_3).await.unwrap()
super::get_image_size_from_url(png_url_3).await.unwrap()
);
assert_eq!(
rotated_jpeg_size,
get_image_size_from_url(rotated_jpeg_url).await.unwrap()
super::get_image_size_from_url(rotated_jpeg_url)
.await
.unwrap()
);
assert_eq!(
webp_size_1,
get_image_size_from_url(webp_url_1).await.unwrap()
super::get_image_size_from_url(webp_url_1).await.unwrap()
);
assert_eq!(
webp_size_2,
get_image_size_from_url(webp_url_2).await.unwrap()
super::get_image_size_from_url(webp_url_2).await.unwrap()
);
assert_eq!(ico_size, get_image_size_from_url(ico_url).await.unwrap());
assert_eq!(gif_size, get_image_size_from_url(gif_url).await.unwrap());
assert!(get_image_size_from_url(mp3_url).await.is_err());
assert_eq!(
ico_size,
super::get_image_size_from_url(ico_url).await.unwrap()
);
assert_eq!(
gif_size,
super::get_image_size_from_url(gif_url).await.unwrap()
);
assert!(super::get_image_size_from_url(mp3_url).await.is_err());
}
#[tokio::test]
@ -212,7 +220,7 @@ mod unit_test {
.await
.unwrap();
assert!(get_image_size_from_url(url).await.is_ok());
assert!(get_image_size_from_url(url).await.is_err());
assert!(super::get_image_size_from_url(url).await.is_ok());
assert!(super::get_image_size_from_url(url).await.is_err());
}
}

View file

@ -15,20 +15,28 @@ pub fn is_safe_url(url: &str) -> bool {
#[cfg(test)]
mod unit_test {
use super::is_safe_url;
#[test]
fn safe_url() {
assert!(is_safe_url("http://firefish.dev/firefish/firefish"));
assert!(is_safe_url("https://firefish.dev/firefish/firefish"));
assert!(is_safe_url("http://firefish.dev:80/firefish/firefish"));
assert!(is_safe_url("https://firefish.dev:80/firefish/firefish"));
assert!(is_safe_url("http://firefish.dev:443/firefish/firefish"));
assert!(is_safe_url("https://firefish.dev:443/firefish/firefish"));
assert!(!is_safe_url("https://unix/firefish/firefish"));
assert!(!is_safe_url("https://firefish.dev:35/firefish/firefish"));
assert!(!is_safe_url("ftp://firefish.dev/firefish/firefish"));
assert!(!is_safe_url("nyaa"));
assert!(!is_safe_url(""));
fn is_safe_url() {
assert!(super::is_safe_url("http://firefish.dev/firefish/firefish"));
assert!(super::is_safe_url("https://firefish.dev/firefish/firefish"));
assert!(super::is_safe_url(
"http://firefish.dev:80/firefish/firefish"
));
assert!(super::is_safe_url(
"https://firefish.dev:80/firefish/firefish"
));
assert!(super::is_safe_url(
"http://firefish.dev:443/firefish/firefish"
));
assert!(super::is_safe_url(
"https://firefish.dev:443/firefish/firefish"
));
assert!(!super::is_safe_url("https://unix/firefish/firefish"));
assert!(!super::is_safe_url(
"https://firefish.dev:35/firefish/firefish"
));
assert!(!super::is_safe_url("ftp://firefish.dev/firefish/firefish"));
assert!(!super::is_safe_url("nyaa"));
assert!(!super::is_safe_url(""));
}
}

View file

@ -100,7 +100,7 @@ mod unit_test {
}
#[tokio::test]
async fn check_version() {
async fn get_latest_version() {
// delete caches in case you run this test multiple times
cache::delete_one(cache::Category::FetchUrl, UPSTREAM_PACKAGE_JSON_URL)
.await

View file

@ -12,24 +12,23 @@ pub fn from_mastodon_id(mastodon_id: &str) -> Option<String> {
#[cfg(test)]
mod unit_test {
use super::{from_mastodon_id, to_mastodon_id};
use pretty_assertions::assert_eq;
#[test]
fn to_mastodon_id_test() {
fn to_mastodon_id() {
assert_eq!(
to_mastodon_id("9pdqi3rjl4lxirq3").unwrap(),
super::to_mastodon_id("9pdqi3rjl4lxirq3").unwrap(),
"2145531976185871567229403"
);
assert_eq!(to_mastodon_id("9pdqi3r*irq3"), None);
assert_eq!(super::to_mastodon_id("9pdqi3r*irq3"), None);
}
#[test]
fn from_mastodon_id_test() {
fn from_mastodon_id() {
assert_eq!(
from_mastodon_id("2145531976185871567229403").unwrap(),
super::from_mastodon_id("2145531976185871567229403").unwrap(),
"9pdqi3rjl4lxirq3"
);
assert_eq!(from_mastodon_id("9pdqi3rjl4lxirq3"), None);
assert_eq!(super::from_mastodon_id("9pdqi3rjl4lxirq3"), None);
}
}

View file

@ -91,7 +91,7 @@ mod unit_test {
}
#[test]
fn summarize() {
fn summarize_note() {
let note = NoteLike {
file_ids: vec![],
text: Some("Hello world!".to_string()),

View file

@ -100,17 +100,28 @@ pub fn nyaify(text: &str, lang: Option<&str>) -> String {
#[cfg(test)]
mod unit_test {
use super::nyaify;
use pretty_assertions::assert_eq;
#[test]
fn can_nyaify() {
assert_eq!(nyaify("Hello everyone!", Some("en")), "Hello everynyan!");
assert_eq!(nyaify("Nonbinary people", None), "Nyanbinyary people");
assert_eq!(nyaify("1分鐘是60秒", Some("zh-TW")), "1分鐘是60喵");
assert_eq!(nyaify("1分間は60秒です", Some("ja-JP")), "1分間は60秒です");
assert_eq!(nyaify("あなたは誰ですか", None), "あにゃたは誰ですか");
assert_eq!(nyaify("Ναυτικός", Some("el-GR")), "Νιαυτικός");
assert_eq!(nyaify("일어나다", None), "일어냐다냥");
fn nyaify() {
assert_eq!(
super::nyaify("Hello everyone!", Some("en")),
"Hello everynyan!"
);
assert_eq!(
super::nyaify("Nonbinary people", None),
"Nyanbinyary people"
);
assert_eq!(super::nyaify("1分鐘是60秒", Some("zh-TW")), "1分鐘是60喵");
assert_eq!(
super::nyaify("1分間は60秒です", Some("ja-JP")),
"1分間は60秒です"
);
assert_eq!(
super::nyaify("あなたは誰ですか", None),
"あにゃたは誰ですか"
);
assert_eq!(super::nyaify("Ναυτικός", Some("el-GR")), "Νιαυτικός");
assert_eq!(super::nyaify("일어나다", None), "일어냐다냥");
}
}

View file

@ -48,14 +48,14 @@ pub fn is_old_password_algorithm(hash: &str) -> bool {
#[cfg(test)]
mod unit_test {
use super::{hash_password, is_old_password_algorithm, verify_password};
use super::{hash_password, is_old_password_algorithm};
#[test]
fn verify_password_test() {
fn verify_password() {
let password = "omWc*%sD^fn7o2cXmc9e2QasBdrbRuhNB*gx!J5";
let hash = hash_password(password).unwrap();
assert!(verify_password(password, hash.as_str()).unwrap());
assert!(super::verify_password(password, hash.as_str()).unwrap());
let argon2_hash = "$argon2id$v=19$m=19456,t=2,p=1$jty3puDFd4ENv/lgHn3ROQ$kRHDdEoVv2rruvnF731E74NxnYlvj5FMgePdGIIq3Jk";
let argon2_invalid_hash = "$argon2id$v=19$m=19456,t=2,p=1$jty3puDFd4ENv/lgHn3ROQ$kRHDdEoVv2rruvnF731E74NxnYlvj4FMgePdGIIq3Jk";
@ -65,10 +65,10 @@ mod unit_test {
assert!(!is_old_password_algorithm(argon2_hash));
assert!(is_old_password_algorithm(bcrypt_hash));
assert!(verify_password(password, argon2_hash).unwrap());
assert!(verify_password(password, bcrypt_hash).unwrap());
assert!(super::verify_password(password, argon2_hash).unwrap());
assert!(super::verify_password(password, bcrypt_hash).unwrap());
assert!(!verify_password(password, argon2_invalid_hash).unwrap());
assert!(!verify_password(password, bcrypt_invalid_hash).unwrap());
assert!(!super::verify_password(password, argon2_invalid_hash).unwrap());
assert!(!super::verify_password(password, bcrypt_invalid_hash).unwrap());
}
}

View file

@ -121,11 +121,11 @@ pub async fn to_db_reaction(reaction: Option<&str>, host: Option<&str>) -> Resul
#[cfg(test)]
mod unit_test {
use super::{decode_reaction, DecodedReaction};
use super::DecodedReaction;
use pretty_assertions::{assert_eq, assert_ne};
#[test]
fn test_decode_reaction() {
fn decode_reaction() {
let unicode_emoji_1 = DecodedReaction {
reaction: "".to_string(),
name: None,
@ -137,25 +137,25 @@ mod unit_test {
host: None,
};
assert_eq!(decode_reaction(""), unicode_emoji_1);
assert_eq!(decode_reaction("🩷"), unicode_emoji_2);
assert_eq!(super::decode_reaction(""), unicode_emoji_1);
assert_eq!(super::decode_reaction("🩷"), unicode_emoji_2);
assert_ne!(decode_reaction(""), unicode_emoji_2);
assert_ne!(decode_reaction("🩷"), unicode_emoji_1);
assert_ne!(super::decode_reaction(""), unicode_emoji_2);
assert_ne!(super::decode_reaction("🩷"), unicode_emoji_1);
let unicode_emoji_3 = DecodedReaction {
reaction: "🖖🏿".to_string(),
name: None,
host: None,
};
assert_eq!(decode_reaction("🖖🏿"), unicode_emoji_3);
assert_eq!(super::decode_reaction("🖖🏿"), unicode_emoji_3);
let local_emoji = DecodedReaction {
reaction: ":meow_melt_tears@.:".to_string(),
name: Some("meow_melt_tears".to_string()),
host: None,
};
assert_eq!(decode_reaction(":meow_melt_tears:"), local_emoji);
assert_eq!(super::decode_reaction(":meow_melt_tears:"), local_emoji);
let remote_emoji_1 = DecodedReaction {
reaction: ":meow_uwu@some-domain.example.org:".to_string(),
@ -163,7 +163,7 @@ mod unit_test {
host: Some("some-domain.example.org".to_string()),
};
assert_eq!(
decode_reaction(":meow_uwu@some-domain.example.org:"),
super::decode_reaction(":meow_uwu@some-domain.example.org:"),
remote_emoji_1
);
@ -173,7 +173,7 @@ mod unit_test {
host: Some("xn--eckwd4c7c.example.org".to_string()),
};
assert_eq!(
decode_reaction(":C++23@xn--eckwd4c7c.example.org:"),
super::decode_reaction(":C++23@xn--eckwd4c7c.example.org:"),
remote_emoji_2
);
@ -182,13 +182,16 @@ mod unit_test {
name: None,
host: None,
};
assert_eq!(decode_reaction(":foo"), invalid_reaction_1);
assert_eq!(super::decode_reaction(":foo"), invalid_reaction_1);
let invalid_reaction_2 = DecodedReaction {
reaction: ":foo&@example.com:".to_string(),
name: None,
host: None,
};
assert_eq!(decode_reaction(":foo&@example.com:"), invalid_reaction_2);
assert_eq!(
super::decode_reaction(":foo&@example.com:"),
invalid_reaction_2
);
}
}

View file

@ -153,7 +153,7 @@ mod unit_test {
use pretty_assertions::assert_eq;
#[test]
fn test_match_all() {
fn check_match_string() {
assert_eq!(match_all("Apple", "apple and banana", false), true);
assert_eq!(match_all("Apple", "apple and banana", true), false);
assert_eq!(match_all("Apple Banana", "apple and banana", false), true);

View file

@ -86,7 +86,7 @@ mod unit_test {
use std::thread;
#[test]
fn can_create_and_decode_id() {
fn create_and_decode_id() {
let now = Utc::now();
assert_eq!(gen_id().len(), 16);
assert_ne!(gen_id_at(now), gen_id_at(now));
@ -108,7 +108,7 @@ mod unit_test {
}
#[test]
fn fixture_id_timestamp_check() {
fn get_timestamp_from_id() {
assert_eq!(get_timestamp("9e112pilk1").unwrap(), 1682499501741);
assert_eq!(get_timestamp("9e183znmxa").unwrap(), 1682511318850);
assert_eq!(get_timestamp("9e9srqr79p").unwrap(), 1683029748787);

View file

@ -19,13 +19,12 @@ pub fn generate_user_token() -> String {
#[cfg(test)]
mod unit_test {
use super::generate_secure_random_string;
use pretty_assertions::{assert_eq, assert_ne};
use std::thread;
use super::generate_secure_random_string;
#[test]
fn can_generate_unique_strings() {
fn generate_unique_strings() {
assert_eq!(generate_secure_random_string(16).len(), 16);
assert_ne!(
generate_secure_random_string(16),