From d0fd8166e327d0810e3516f4d9dff99cae9e06f7 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Tue, 17 May 2022 20:12:30 +0530 Subject: [PATCH] feat: add federation file writes in crawl method --- src/spider.rs | 10 +++++++--- src/tests.rs | 11 +++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/spider.rs b/src/spider.rs index 9ac55dc..42fdb17 100644 --- a/src/spider.rs +++ b/src/spider.rs @@ -26,9 +26,10 @@ use gitea::Gitea; use crate::ctx::Ctx; use crate::db::BoxDB; +use crate::federate::BoxFederate; impl Ctx { - pub async fn crawl(&self, instance_url: &str, db: &BoxDB) { + pub async fn crawl(&self, instance_url: &str, db: &BoxDB, federate: &BoxFederate) { let gitea = Gitea::new(Url::parse(instance_url).unwrap(), self.client.clone()); let mut page = 1; let hostname = gitea.get_hostname(); @@ -38,6 +39,7 @@ impl Ctx { forge_type: gitea.forge_type(), }; db.create_forge_isntance(&msg).await.unwrap(); + federate.create_forge_isntance(&msg).await.unwrap(); } loop { @@ -62,6 +64,7 @@ impl Ctx { { let msg = u.as_ref().into(); db.add_user(&msg).await.unwrap(); + federate.create_user(&msg).await.unwrap(); } } @@ -73,6 +76,7 @@ impl Ctx { { let msg = r.into(); db.create_repository(&msg).await.unwrap(); + federate.create_repository(&msg).await.unwrap(); } } @@ -94,8 +98,8 @@ mod tests { #[actix_rt::test] async fn crawl_gitea() { - let (db, ctx) = sqlx_sqlite::get_ctx().await; - ctx.crawl(GITEA_HOST, &db).await; + let (db, ctx, federate, _tmp_dir) = sqlx_sqlite::get_ctx().await; + ctx.crawl(GITEA_HOST, &db, &federate).await; let hostname = get_hostname(&Url::parse(GITEA_HOST).unwrap()); assert!(db.forge_exists(&hostname).await.unwrap()); assert!(db diff --git a/src/tests.rs b/src/tests.rs index 48db49c..c9c14b2 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -21,6 +21,7 @@ pub use std::sync::Arc; use crate::ctx::Ctx; pub use crate::db::BoxDB; +pub use crate::federate::{get_federate, BoxFederate}; use crate::settings::{DBType, Settings}; //pub mod sqlx_postgres { @@ -38,8 +39,9 @@ use crate::settings::{DBType, Settings}; pub mod sqlx_sqlite { use super::*; use crate::db::sqlite; + use mktemp::Temp; - pub async fn get_ctx() -> (BoxDB, Arc) { + pub async fn get_ctx() -> (BoxDB, Arc, BoxFederate, Temp) { let url = env::var("SQLITE_DATABASE_URL").unwrap(); env::set_var("DATABASE_URL", &url); println!("found db url: {url}"); @@ -47,6 +49,11 @@ pub mod sqlx_sqlite { settings.database.url = url.clone(); settings.database.database_type = DBType::Sqlite; let db = sqlite::get_data(Some(settings.clone())).await; - (db, Ctx::new(settings).await) + + let tmp_dir = Temp::new_dir().unwrap(); + settings.repository.root = tmp_dir.to_str().unwrap().to_string(); + let federate = get_federate(Some(settings.clone())).await; + + (db, Ctx::new(settings).await, federate, tmp_dir) } }