mirror of
https://github.com/Nutomic/ibis.git
synced 2024-11-22 08:41:08 +00:00
fix tests
This commit is contained in:
parent
c8925fe2f3
commit
1469e06bf2
5 changed files with 25 additions and 21 deletions
|
@ -1,6 +1,3 @@
|
|||
# Address where ibis should listen for incoming requests
|
||||
bind = "127.0.0.1:8081"
|
||||
|
||||
# Whether users can create new accounts
|
||||
registration_open = true
|
||||
|
||||
|
|
|
@ -38,9 +38,10 @@ use diesel::{
|
|||
PgConnection,
|
||||
};
|
||||
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 log::info;
|
||||
use std::net::SocketAddr;
|
||||
use tokio::net::TcpListener;
|
||||
use tower_http::cors::CorsLayer;
|
||||
use tower_layer::Layer;
|
||||
|
@ -58,7 +59,7 @@ const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations");
|
|||
|
||||
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 db_pool = Pool::builder()
|
||||
.max_size(config.database.pool_size)
|
||||
|
@ -82,8 +83,11 @@ pub async fn start(config: IbisConfig) -> MyResult<()> {
|
|||
setup(&data.to_request_data()).await?;
|
||||
}
|
||||
|
||||
let leptos_options = get_config_from_str(include_str!("../../Cargo.toml"))?;
|
||||
let addr = leptos_options.site_addr;
|
||||
let leptos_options = get_configuration(Some("Cargo.toml")).await?.leptos_options;
|
||||
let mut addr = leptos_options.site_addr;
|
||||
if let Some(override_hostname) = override_hostname {
|
||||
addr = override_hostname;
|
||||
}
|
||||
let routes = generate_route_list(App);
|
||||
|
||||
let config = data.clone();
|
||||
|
|
|
@ -16,7 +16,7 @@ pub async fn main() -> ibis::backend::error::MyResult<()> {
|
|||
.init();
|
||||
|
||||
let ibis_config = IbisConfig::read()?;
|
||||
ibis::backend::start(ibis_config).await?;
|
||||
ibis::backend::start(ibis_config, None).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ use std::{
|
|||
thread::{sleep, spawn},
|
||||
time::Duration,
|
||||
};
|
||||
use tokio::task::JoinHandle;
|
||||
use tokio::{join, task::JoinHandle};
|
||||
use tracing::log::LevelFilter;
|
||||
|
||||
pub struct TestData {
|
||||
|
@ -66,11 +66,13 @@ impl TestData {
|
|||
j.join().unwrap();
|
||||
}
|
||||
|
||||
Self {
|
||||
alpha: IbisInstance::start(alpha_db_path, port_alpha, "alpha").await,
|
||||
beta: IbisInstance::start(beta_db_path, port_beta, "beta").await,
|
||||
gamma: IbisInstance::start(gamma_db_path, port_gamma, "gamma").await,
|
||||
}
|
||||
let (alpha, beta, gamma) = join!(
|
||||
IbisInstance::start(alpha_db_path, port_alpha, "alpha"),
|
||||
IbisInstance::start(beta_db_path, port_beta, "beta"),
|
||||
IbisInstance::start(gamma_db_path, port_gamma, "gamma")
|
||||
);
|
||||
|
||||
Self { alpha, beta, gamma }
|
||||
}
|
||||
|
||||
pub fn stop(self) -> MyResult<()> {
|
||||
|
@ -115,7 +117,8 @@ impl IbisInstance {
|
|||
|
||||
async fn start(db_path: String, port: i32, username: &str) -> Self {
|
||||
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 {
|
||||
database: IbisConfigDatabase {
|
||||
connection_url,
|
||||
|
@ -123,13 +126,17 @@ impl IbisInstance {
|
|||
},
|
||||
registration_open: true,
|
||||
federation: IbisConfigFederation {
|
||||
domain: hostname.clone(),
|
||||
domain: domain.clone(),
|
||||
..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 {
|
||||
start(config).await.unwrap();
|
||||
start(config, Some(hostname.parse().unwrap()))
|
||||
.await
|
||||
.unwrap();
|
||||
});
|
||||
// wait a moment for the backend to start
|
||||
tokio::time::sleep(Duration::from_millis(5000)).await;
|
||||
|
@ -137,8 +144,6 @@ impl IbisInstance {
|
|||
username: username.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();
|
||||
Self {
|
||||
api_client,
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#![allow(clippy::unwrap_used)]
|
||||
|
||||
extern crate ibis;
|
||||
|
||||
mod common;
|
||||
|
||||
use crate::common::{TestData, TEST_ARTICLE_DEFAULT_TEXT};
|
||||
|
|
Loading…
Reference in a new issue