Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Oct 25, 2023
1 parent 0a6628c commit 65e489d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 33 deletions.
39 changes: 20 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 7 additions & 12 deletions crates/kitsune-core/src/activitypub/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ mod test {
use kitsune_db::{model::account::Account, schema::accounts};
use kitsune_http_client::Client;
use kitsune_search::NoopSearchService;
use kitsune_test::database_test;
use kitsune_test::{build_ap_response, database_test};
use kitsune_type::{
ap::{
actor::{Actor, ActorType, PublicKey},
Expand Down Expand Up @@ -612,6 +612,7 @@ mod test {
let client = service_fn(move |req: Request<_>| {
let count = request_counter.fetch_add(1, Ordering::SeqCst);
assert!(MAX_FETCH_DEPTH * 3 >= count);

async move {
let author_id = "https://example.com/users/1".to_owned();
let author = Actor {
Expand Down Expand Up @@ -658,11 +659,14 @@ mod test {
to: vec![PUBLIC_IDENTIFIER.into()],
cc: Vec::new(),
};

let body = simd_json::to_string(&note).unwrap();
Ok::<_, Infallible>(Response::new(Body::from(body)))

Ok::<_, Infallible>(build_ap_response!(body))
} else if req.uri().path_and_query().unwrap() == Uri::try_from(&author.id).unwrap().path_and_query().unwrap() {
let body = simd_json::to_string(&author).unwrap();
Ok::<_, Infallible>(Response::new(Body::from(body)))

Ok::<_, Infallible>(build_ap_response!(body))
} else {
handle(req).await
}
Expand Down Expand Up @@ -886,15 +890,6 @@ mod test {
}

async fn handle(req: Request<Body>) -> Result<Response<Body>, Infallible> {
macro_rules! build_ap_response {
($body:expr) => {
Response::builder()
.header("Content-Type", "application/activity+json")
.body(Body::from($body))
.unwrap()
};
}

match req.uri().path_and_query().unwrap().as_str() {
"/users/0x0" => {
let body = include_str!("../../../../test-fixtures/0x0_actor.json");
Expand Down
4 changes: 2 additions & 2 deletions crates/kitsune-core/src/resolve/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ mod test {
use kitsune_http_client::Client;
use kitsune_search::NoopSearchService;
use kitsune_storage::fs::Storage as FsStorage;
use kitsune_test::{database_test, redis_test};
use kitsune_test::{build_ap_response, database_test, redis_test};
use pretty_assertions::assert_eq;
use scoped_futures::ScopedFutureExt;
use std::sync::Arc;
Expand All @@ -117,7 +117,7 @@ mod test {
}
"/users/0x0" => {
let body = include_str!("../../../../test-fixtures/0x0_actor.json");
Ok::<_, Infallible>(Response::new(Body::from(body)))
Ok::<_, Infallible>(build_ap_response!(body))
}
path => panic!("HTTP client hit unexpected route: {path}"),
}
Expand Down
1 change: 1 addition & 0 deletions crates/kitsune-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ deadpool-redis = "0.13.0"
diesel = "2.1.3"
diesel-async = "0.4.1"
futures-util = "0.3.28"
http = "0.2.9"
kitsune-db = { path = "../kitsune-db" }
pin-project-lite = "0.2.13"
redis = "0.23.3"
Expand Down
13 changes: 13 additions & 0 deletions crates/kitsune-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,21 @@ use std::{env, error::Error, panic};

mod catch_panic;

#[doc(hidden)]
pub use http;

type BoxError = Box<dyn Error + Send + Sync>;

#[macro_export]
macro_rules! build_ap_response {
($body:expr) => {
$crate::http::Response::builder()
.header("Content-Type", "application/activity+json")
.body(Body::from($body))
.unwrap()
};
}

pub async fn database_test<F, Fut>(func: F) -> Fut::Output
where
F: FnOnce(PgPool) -> Fut,
Expand Down

0 comments on commit 65e489d

Please sign in to comment.