1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-11-22 19:41:09 +00:00

fix tests

This commit is contained in:
Felix Ableitner 2024-10-28 15:28:40 +01:00
parent c8925fe2f3
commit 1469e06bf2
5 changed files with 25 additions and 21 deletions

View file

@ -1,6 +1,3 @@
# Address where ibis should listen for incoming requests
bind = "127.0.0.1:8081"
# Whether users can create new accounts # Whether users can create new accounts
registration_open = true registration_open = true

View file

@ -38,9 +38,10 @@ use diesel::{
PgConnection, PgConnection,
}; };
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}; use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
use leptos::leptos_config::get_config_from_str; use leptos::get_configuration;
use leptos_axum::{generate_route_list, LeptosRoutes}; use leptos_axum::{generate_route_list, LeptosRoutes};
use log::info; use log::info;
use std::net::SocketAddr;
use tokio::net::TcpListener; use tokio::net::TcpListener;
use tower_http::cors::CorsLayer; use tower_http::cors::CorsLayer;
use tower_layer::Layer; use tower_layer::Layer;
@ -58,7 +59,7 @@ const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations");
const FEDERATION_ROUTES_PREFIX: &str = "/federation_routes"; const FEDERATION_ROUTES_PREFIX: &str = "/federation_routes";
pub async fn start(config: IbisConfig) -> MyResult<()> { pub async fn start(config: IbisConfig, override_hostname: Option<SocketAddr>) -> MyResult<()> {
let manager = ConnectionManager::<PgConnection>::new(&config.database.connection_url); let manager = ConnectionManager::<PgConnection>::new(&config.database.connection_url);
let db_pool = Pool::builder() let db_pool = Pool::builder()
.max_size(config.database.pool_size) .max_size(config.database.pool_size)
@ -82,8 +83,11 @@ pub async fn start(config: IbisConfig) -> MyResult<()> {
setup(&data.to_request_data()).await?; setup(&data.to_request_data()).await?;
} }
let leptos_options = get_config_from_str(include_str!("../../Cargo.toml"))?; let leptos_options = get_configuration(Some("Cargo.toml")).await?.leptos_options;
let addr = leptos_options.site_addr; let mut addr = leptos_options.site_addr;
if let Some(override_hostname) = override_hostname {
addr = override_hostname;
}
let routes = generate_route_list(App); let routes = generate_route_list(App);
let config = data.clone(); let config = data.clone();

View file

@ -16,7 +16,7 @@ pub async fn main() -> ibis::backend::error::MyResult<()> {
.init(); .init();
let ibis_config = IbisConfig::read()?; let ibis_config = IbisConfig::read()?;
ibis::backend::start(ibis_config).await?; ibis::backend::start(ibis_config, None).await?;
Ok(()) Ok(())
} }

View file

@ -21,7 +21,7 @@ use std::{
thread::{sleep, spawn}, thread::{sleep, spawn},
time::Duration, time::Duration,
}; };
use tokio::task::JoinHandle; use tokio::{join, task::JoinHandle};
use tracing::log::LevelFilter; use tracing::log::LevelFilter;
pub struct TestData { pub struct TestData {
@ -66,11 +66,13 @@ impl TestData {
j.join().unwrap(); j.join().unwrap();
} }
Self { let (alpha, beta, gamma) = join!(
alpha: IbisInstance::start(alpha_db_path, port_alpha, "alpha").await, IbisInstance::start(alpha_db_path, port_alpha, "alpha"),
beta: IbisInstance::start(beta_db_path, port_beta, "beta").await, IbisInstance::start(beta_db_path, port_beta, "beta"),
gamma: IbisInstance::start(gamma_db_path, port_gamma, "gamma").await, IbisInstance::start(gamma_db_path, port_gamma, "gamma")
} );
Self { alpha, beta, gamma }
} }
pub fn stop(self) -> MyResult<()> { pub fn stop(self) -> MyResult<()> {
@ -115,7 +117,8 @@ impl IbisInstance {
async fn start(db_path: String, port: i32, username: &str) -> Self { async fn start(db_path: String, port: i32, username: &str) -> Self {
let connection_url = format!("postgresql://ibis:password@/ibis?host={db_path}"); let connection_url = format!("postgresql://ibis:password@/ibis?host={db_path}");
let hostname = format!("localhost:{port}"); let hostname = format!("127.0.0.1:{port}");
let domain = format!("localhost:{port}");
let config = IbisConfig { let config = IbisConfig {
database: IbisConfigDatabase { database: IbisConfigDatabase {
connection_url, connection_url,
@ -123,13 +126,17 @@ impl IbisInstance {
}, },
registration_open: true, registration_open: true,
federation: IbisConfigFederation { federation: IbisConfigFederation {
domain: hostname.clone(), domain: domain.clone(),
..Default::default() ..Default::default()
}, },
..Default::default() ..Default::default()
}; };
let client = ClientBuilder::new().cookie_store(true).build().unwrap();
let api_client = ApiClient::new(client, Some(domain));
let handle = tokio::task::spawn(async move { let handle = tokio::task::spawn(async move {
start(config).await.unwrap(); start(config, Some(hostname.parse().unwrap()))
.await
.unwrap();
}); });
// wait a moment for the backend to start // wait a moment for the backend to start
tokio::time::sleep(Duration::from_millis(5000)).await; tokio::time::sleep(Duration::from_millis(5000)).await;
@ -137,8 +144,6 @@ impl IbisInstance {
username: username.to_string(), username: username.to_string(),
password: "hunter2".to_string(), password: "hunter2".to_string(),
}; };
let client = ClientBuilder::new().cookie_store(true).build().unwrap();
let api_client = ApiClient::new(client, Some(hostname));
api_client.register(form).await.unwrap(); api_client.register(form).await.unwrap();
Self { Self {
api_client, api_client,

View file

@ -1,7 +1,5 @@
#![allow(clippy::unwrap_used)] #![allow(clippy::unwrap_used)]
extern crate ibis;
mod common; mod common;
use crate::common::{TestData, TEST_ARTICLE_DEFAULT_TEXT}; use crate::common::{TestData, TEST_ARTICLE_DEFAULT_TEXT};