Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 11m16s
49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
use reqwest::Client;
|
|
use std::time::Duration;
|
|
use rhythm_backend::{controller, state::AppState};
|
|
use axum::Router;
|
|
use sqlx::PgPool;
|
|
use std::sync::Arc;
|
|
use dashmap::DashMap;
|
|
|
|
pub async fn setup_app() -> (Router, PgPool) {
|
|
let db_url = "postgres://user:password@localhost:5432/rhythm-dev?sslmode=disable";
|
|
|
|
let db = PgPool::connect(db_url)
|
|
.await
|
|
.expect("Failed to connect to Postgres at localhost:5432");
|
|
|
|
sqlx::migrate!("./migrations")
|
|
.run(&db)
|
|
.await
|
|
.expect("Failed to run migrations");
|
|
|
|
let state = AppState {
|
|
db: db.clone(),
|
|
jwt_secret: "test-secret-key-12345678901234567890".to_string(),
|
|
rate_limit: Arc::new(DashMap::new()),
|
|
};
|
|
|
|
let app = controller::router(state.clone()).with_state(state);
|
|
(app, db)
|
|
}
|
|
|
|
pub async fn spawn_server(app: axum::Router) -> (String, Client) {
|
|
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
|
|
let port = listener.local_addr().unwrap().port();
|
|
|
|
tokio::spawn(async move {
|
|
axum::serve(listener, app.into_make_service()).await.unwrap();
|
|
});
|
|
|
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
|
|
|
let base_url = format!("http://127.0.0.1:{}", port);
|
|
let client = Client::builder()
|
|
.cookie_store(true)
|
|
.build()
|
|
.unwrap();
|
|
|
|
(base_url, client)
|
|
}
|