Fix tests to follow API changes

This commit is contained in:
Kitaiti Makoto 2021-01-09 01:08:31 +09:00
parent cd5895d560
commit a0cd9dd6bd
7 changed files with 23 additions and 35 deletions

View file

@ -497,10 +497,8 @@ pub(crate) mod tests {
use super::*; use super::*;
use crate::{ use crate::{
blog_authors::*, blog_authors::*,
config::CONFIG,
instance::tests as instance_tests, instance::tests as instance_tests,
medias::NewMedia, medias::NewMedia,
search::tests::get_searcher,
tests::{db, rockets}, tests::{db, rockets},
users::tests as usersTests, users::tests as usersTests,
Connection as Conn, Connection as Conn,
@ -767,9 +765,7 @@ pub(crate) mod tests {
conn.test_transaction::<_, (), _>(|| { conn.test_transaction::<_, (), _>(|| {
let (_, blogs) = fill_database(conn); let (_, blogs) = fill_database(conn);
blogs[0] blogs[0].delete(conn).unwrap();
.delete(conn, &get_searcher(&CONFIG.search_tokenizers))
.unwrap();
assert!(Blog::get(conn, blogs[0].id).is_err()); assert!(Blog::get(conn, blogs[0].id).is_err());
Ok(()) Ok(())
}) })
@ -779,7 +775,6 @@ pub(crate) mod tests {
fn delete_via_user() { fn delete_via_user() {
let conn = &db(); let conn = &db();
conn.test_transaction::<_, (), _>(|| { conn.test_transaction::<_, (), _>(|| {
let searcher = get_searcher(&CONFIG.search_tokenizers);
let (user, _) = fill_database(conn); let (user, _) = fill_database(conn);
let b1 = Blog::insert( let b1 = Blog::insert(
@ -836,10 +831,10 @@ pub(crate) mod tests {
) )
.unwrap(); .unwrap();
user[0].delete(conn, &searcher).unwrap(); user[0].delete(conn).unwrap();
assert!(Blog::get(conn, blog[0].id).is_ok()); assert!(Blog::get(conn, blog[0].id).is_ok());
assert!(Blog::get(conn, blog[1].id).is_err()); assert!(Blog::get(conn, blog[1].id).is_err());
user[1].delete(conn, &searcher).unwrap(); user[1].delete(conn).unwrap();
assert!(Blog::get(conn, blog[0].id).is_err()); assert!(Blog::get(conn, blog[0].id).is_err());
Ok(()) Ok(())
}) })
@ -886,7 +881,7 @@ pub(crate) mod tests {
let _: Blog = blogs[0].save_changes(conn).unwrap(); let _: Blog = blogs[0].save_changes(conn).unwrap();
let ap_repr = blogs[0].to_activity(conn).unwrap(); let ap_repr = blogs[0].to_activity(conn).unwrap();
blogs[0].delete(conn, &*r.searcher).unwrap(); blogs[0].delete(conn).unwrap();
let blog = Blog::from_activity(&r, ap_repr).unwrap(); let blog = Blog::from_activity(&r, ap_repr).unwrap();
assert_eq!(blog.actor_id, blogs[0].actor_id); assert_eq!(blog.actor_id, blogs[0].actor_id);

View file

@ -97,7 +97,6 @@ pub(crate) mod tests {
source: String::new(), source: String::new(),
cover_id: None, cover_id: None,
}, },
&rockets.searcher,
) )
.unwrap(); .unwrap();

View file

@ -316,6 +316,10 @@ mod tests {
db_conn::DbConn((*DB_POOL).get().unwrap()) db_conn::DbConn((*DB_POOL).get().unwrap())
} }
pub(crate) fn pool() -> &'static db_conn::DbPool {
&*DB_POOL
}
lazy_static! { lazy_static! {
static ref DB_POOL: db_conn::DbPool = { static ref DB_POOL: db_conn::DbPool = {
let pool = db_conn::DbPool::builder() let pool = db_conn::DbPool::builder()

View file

@ -893,7 +893,7 @@ mod tests {
) )
.unwrap(); .unwrap();
let create = post.create_activity(conn).unwrap(); let create = post.create_activity(conn).unwrap();
post.delete(conn, &r.searcher).unwrap(); post.delete(conn).unwrap();
match inbox(&r, serde_json::to_value(create).unwrap()).unwrap() { match inbox(&r, serde_json::to_value(create).unwrap()).unwrap() {
InboxResult::Post(p) => { InboxResult::Post(p) => {

View file

@ -8,21 +8,21 @@ pub use self::tokenizer::TokenizerKind;
#[cfg(test)] #[cfg(test)]
pub(crate) mod tests { pub(crate) mod tests {
use super::{Query, Searcher, TokenizerKind}; use super::{actor::SearchActor, Query, Searcher, TokenizerKind};
use diesel::Connection;
use plume_common::utils::random_hex;
use std::env::temp_dir;
use std::str::FromStr;
use crate::{ use crate::{
blogs::tests::fill_database, blogs::tests::fill_database,
config::SearchTokenizerConfig, config::SearchTokenizerConfig,
post_authors::*, post_authors::*,
posts::{NewPost, Post}, posts::{NewPost, Post},
safe_string::SafeString, safe_string::SafeString,
tests::db, tests::pool,
CONFIG, CONFIG,
}; };
use diesel::Connection;
use plume_common::utils::random_hex;
use std::env::temp_dir;
use std::str::FromStr;
use std::sync::Arc;
pub(crate) fn get_searcher(tokenizers: &SearchTokenizerConfig) -> Searcher { pub(crate) fn get_searcher(tokenizers: &SearchTokenizerConfig) -> Searcher {
let dir = temp_dir().join(&format!("plume-test-{}", random_hex())); let dir = temp_dir().join(&format!("plume-test-{}", random_hex()));
@ -122,9 +122,12 @@ pub(crate) mod tests {
#[test] #[test]
fn search() { fn search() {
let conn = &db(); let pool = pool();
let conn = &pool.get().unwrap();
conn.test_transaction::<_, (), _>(|| { conn.test_transaction::<_, (), _>(|| {
let searcher = get_searcher(&CONFIG.search_tokenizers); let searcher = Arc::new(get_searcher(&CONFIG.search_tokenizers));
SearchActor::init(searcher.clone(), pool.clone());
let blog = &fill_database(conn).1[0]; let blog = &fill_database(conn).1[0];
let author = &blog.list_authors(conn).unwrap()[0]; let author = &blog.list_authors(conn).unwrap()[0];
@ -145,7 +148,6 @@ pub(crate) mod tests {
source: "".to_owned(), source: "".to_owned(),
cover_id: None, cover_id: None,
}, },
&searcher,
) )
.unwrap(); .unwrap();
PostAuthor::insert( PostAuthor::insert(
@ -165,7 +167,7 @@ pub(crate) mod tests {
let newtitle = random_hex()[..8].to_owned(); let newtitle = random_hex()[..8].to_owned();
post.title = newtitle.clone(); post.title = newtitle.clone();
post.update(conn, &searcher).unwrap(); post.update(conn).unwrap();
searcher.commit(); searcher.commit();
assert_eq!( assert_eq!(
searcher.search_document(conn, Query::from_str(&newtitle).unwrap(), (0, 1))[0].id, searcher.search_document(conn, Query::from_str(&newtitle).unwrap(), (0, 1))[0].id,
@ -175,7 +177,7 @@ pub(crate) mod tests {
.search_document(conn, Query::from_str(&title).unwrap(), (0, 1)) .search_document(conn, Query::from_str(&title).unwrap(), (0, 1))
.is_empty()); .is_empty());
post.delete(conn, &searcher).unwrap(); post.delete(conn).unwrap();
searcher.commit(); searcher.commit();
assert!(searcher assert!(searcher
.search_document(conn, Query::from_str(&newtitle).unwrap(), (0, 1)) .search_document(conn, Query::from_str(&newtitle).unwrap(), (0, 1))
@ -214,7 +216,6 @@ pub(crate) mod tests {
source: "".to_owned(), source: "".to_owned(),
cover_id: None, cover_id: None,
}, },
&searcher,
) )
.unwrap(); .unwrap();

View file

@ -408,7 +408,6 @@ mod tests {
source: "you must say GNU/Linux, not Linux!!!".to_string(), source: "you must say GNU/Linux, not Linux!!!".to_string(),
cover_id: None, cover_id: None,
}, },
&r.searcher,
) )
.unwrap(); .unwrap();
assert!(gnu_tl.matches(r, &gnu_post, Kind::Original).unwrap()); assert!(gnu_tl.matches(r, &gnu_post, Kind::Original).unwrap());
@ -428,7 +427,6 @@ mod tests {
source: "so is Microsoft".to_string(), source: "so is Microsoft".to_string(),
cover_id: None, cover_id: None,
}, },
&r.searcher,
) )
.unwrap(); .unwrap();
assert!(!gnu_tl.matches(r, &non_free_post, Kind::Original).unwrap()); assert!(!gnu_tl.matches(r, &non_free_post, Kind::Original).unwrap());
@ -481,7 +479,6 @@ mod tests {
subtitle: "".to_string(), subtitle: "".to_string(),
cover_id: None, cover_id: None,
}, },
&r.searcher,
) )
.unwrap(); .unwrap();
assert!(my_tl.matches(r, &post, Kind::Original).unwrap()); // matches because of "blog in fav_blogs" (and there is no cover) assert!(my_tl.matches(r, &post, Kind::Original).unwrap()); // matches because of "blog in fav_blogs" (and there is no cover)
@ -503,7 +500,6 @@ mod tests {
subtitle: "".to_string(), subtitle: "".to_string(),
cover_id: None, cover_id: None,
}, },
&r.searcher,
) )
.unwrap(); .unwrap();
assert!(!my_tl.matches(r, &post, Kind::Like(&users[1])).unwrap()); assert!(!my_tl.matches(r, &post, Kind::Like(&users[1])).unwrap());
@ -549,7 +545,6 @@ mod tests {
source: "you must say GNU/Linux, not Linux!!!".to_string(), source: "you must say GNU/Linux, not Linux!!!".to_string(),
cover_id: None, cover_id: None,
}, },
&r.searcher,
) )
.unwrap(); .unwrap();
@ -568,7 +563,6 @@ mod tests {
source: "so is Microsoft".to_string(), source: "so is Microsoft".to_string(),
cover_id: None, cover_id: None,
}, },
&r.searcher,
) )
.unwrap(); .unwrap();
@ -608,7 +602,6 @@ mod tests {
source: "you must say GNU/Linux, not Linux!!!".to_string(), source: "you must say GNU/Linux, not Linux!!!".to_string(),
cover_id: None, cover_id: None,
}, },
&r.searcher,
) )
.unwrap(); .unwrap();
gnu_post gnu_post
@ -745,7 +738,6 @@ mod tests {
source: "you must say GNU/Linux, not Linux!!!".to_string(), source: "you must say GNU/Linux, not Linux!!!".to_string(),
cover_id: None, cover_id: None,
}, },
&r.searcher,
) )
.unwrap(); .unwrap();
gnu_post.update_tags(conn, vec![Tag::build_activity("free".to_owned()).unwrap()]).unwrap(); gnu_post.update_tags(conn, vec![Tag::build_activity("free".to_owned()).unwrap()]).unwrap();
@ -779,7 +771,6 @@ mod tests {
source: "you must say GNU/Linux, not Linux!!!".to_string(), source: "you must say GNU/Linux, not Linux!!!".to_string(),
cover_id: None, cover_id: None,
}, },
&r.searcher,
) )
.unwrap(); .unwrap();

View file

@ -1130,9 +1130,7 @@ impl NewUser {
pub(crate) mod tests { pub(crate) mod tests {
use super::*; use super::*;
use crate::{ use crate::{
config::CONFIG,
instance::{tests as instance_tests, Instance}, instance::{tests as instance_tests, Instance},
search::tests::get_searcher,
tests::{db, rockets}, tests::{db, rockets},
Connection as Conn, Connection as Conn,
}; };