Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix all router endpoint integration tests #36

Merged
merged 3 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 77 additions & 2 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions entity_api/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ pub struct Credentials {
}

impl Backend {
pub fn new(db: &DatabaseConnection) -> Self {
pub fn new(db: &Arc<DatabaseConnection>) -> Self {
info!("** Backend::new()");
Self {
db: Arc::new(db.clone()),
// Arc is cloned, but the inner DatabaseConnection refers to the same instance
// as the one passed in to new() (see the Arc documentation for more info)
db: Arc::clone(db),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ pub struct AppState {
}

impl AppState {
pub fn new(app_config: Config, db: DatabaseConnection) -> Self {
pub fn new(app_config: Config, db: &Arc<DatabaseConnection>) -> Self {
Self {
database_connection: Arc::new(db),
database_connection: Arc::clone(db),
config: app_config,
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use log::*;
use service::{config::Config, logging::Logger, AppState};
use std::sync::Arc;

#[tokio::main]
async fn main() {
Expand All @@ -33,9 +34,9 @@ async fn main() {

info!("Starting up...");

let db = service::init_database(config.database_uri()).await.unwrap();
let db = Arc::new(service::init_database(config.database_uri()).await.unwrap());

let app_state = AppState::new(config, db);
let app_state = AppState::new(config, &db);

entity_api::seed_database(app_state.db_conn_ref()).await;

Expand Down
4 changes: 3 additions & 1 deletion web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ mock = ["sea-orm/mock"]

[dev-dependencies]
anyhow = "1.0.76"
reqwest = { version = "0.11.23", features = ["json"] }
chrono = { version = "0.4.34", features = ["serde"] }
password-auth = "1.0.0"
reqwest = { version = "0.11.23", features = ["json", "cookies"] }
2 changes: 1 addition & 1 deletion web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub async fn init_server(app_state: AppState) -> Result<()> {
.with_expiry(Expiry::OnInactivity(Duration::days(1)));

// Auth service
let backend = Backend::new(app_state.db_conn_ref());
let backend = Backend::new(&app_state.database_connection);
let auth_layer = AuthManagerLayerBuilder::new(backend, session_layer).build();

// These will probably come from app_state.config (command line)
Expand Down
Loading
Loading