diff --git a/.vscode/settings.json b/.vscode/settings.json index 3415779..5dd7f56 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,6 @@ { "rust-analyzer.linkedProjects": [ "./link-for-later/Cargo.toml", - "./link-for-later-axum/Cargo.toml", "./link-for-later-lambda/Cargo.toml", "./link-for-later-shuttle/Cargo.toml", ] diff --git a/Cargo.lock b/Cargo.lock index bad8d45..55c0842 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,9 +62,9 @@ checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" [[package]] name = "anyhow" -version = "1.0.76" +version = "1.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59d2a3357dde987206219e78ecfbbb6e8dad06cbb65292758d3270e6254f7355" +checksum = "c9d19de80eff169429ac1e9f48fffb163916b448a44e8e046186232046d9e1f9" [[package]] name = "argon2" @@ -1359,21 +1359,8 @@ dependencies = [ "tokio", "tower", "tracing", - "tracing-test", - "validator", -] - -[[package]] -name = "link-for-later-axum" -version = "0.1.0" -dependencies = [ - "axum 0.7.2", - "link-for-later", - "mongodb", - "tokio", - "tower", - "tracing", "tracing-subscriber", + "validator", ] [[package]] @@ -1400,6 +1387,7 @@ dependencies = [ "shuttle-shared-db", "tokio", "tracing", + "tracing-subscriber", ] [[package]] @@ -2097,9 +2085,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "relative-path" -version = "1.9.0" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c707298afce11da2efef2f600116fa93ffa7a032b5d7b628aa17711ec81383ca" +checksum = "e898588f33fdd5b9420719948f9f2a32c922a246964576f71ba7f24f80610fbc" [[package]] name = "resolv-conf" @@ -2305,9 +2293,9 @@ dependencies = [ [[package]] name = "serde_bytes" -version = "0.11.12" +version = "0.11.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab33ec92f677585af6d88c65593ae2375adde54efdbf16d597f2cbc7a6d368ff" +checksum = "8bb1879ea93538b78549031e2d54da3e901fd7e75f2e4dc758d760937b123d10" dependencies = [ "serde", ] @@ -2753,18 +2741,18 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" [[package]] name = "thiserror" -version = "1.0.51" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +checksum = "83a48fd946b02c0a526b2e9481c8e2a17755e47039164a86c4070446e3a4614d" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.51" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +checksum = "e7fbe9b594d6568a6a1443250a7e67d80b74e1e96f6d1715e1e21cc1888291d3" dependencies = [ "proc-macro2", "quote", @@ -3100,29 +3088,6 @@ dependencies = [ "tracing-serde", ] -[[package]] -name = "tracing-test" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a2c0ff408fe918a94c428a3f2ad04e4afd5c95bbc08fcf868eff750c15728a4" -dependencies = [ - "lazy_static", - "tracing-core", - "tracing-subscriber", - "tracing-test-macro", -] - -[[package]] -name = "tracing-test-macro" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258bc1c4f8e2e73a977812ab339d503e6feeb92700f6d07a6de4d321522d5c08" -dependencies = [ - "lazy_static", - "quote", - "syn 1.0.109", -] - [[package]] name = "trust-dns-proto" version = "0.21.2" diff --git a/README.md b/README.md index 2ea3b20..93aa089 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,9 @@ Link for Later Service provides an API to save links in your personal library fo - [`Axum`](https://github.com/tokio-rs/axum) as web application framework - Multiple deployment options: - - [Shuttle](https://github.com/shuttle-hq/shuttle). Refer [here](./link-for-later-shuttle/) for details. + - [Shuttle](https://github.com/shuttle-hq/shuttle) application. Refer [here](./link-for-later-shuttle/) for details. - [Cargo Lambda](https://www.cargo-lambda.info/) to deploy the service as an AWS Lambda Function. Refer [here](./link-for-later-lambda/) for details. - - Standalone server using axum for local development. Refer [here](./link-for-later-axum/) for details. + - Standalone server using axum for local development. Refer [here](./link-for-later/src/bin/) for details. - Multiple repository options: - MongoDB - InMemory database diff --git a/link-for-later-axum/Cargo.toml b/link-for-later-axum/Cargo.toml deleted file mode 100644 index 6161e7b..0000000 --- a/link-for-later-axum/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "link-for-later-axum" -version = "0.1.0" -edition = "2021" -description = "Link for Later Service in Axum" -repository = "https://github.com/kentSarmiento/link-for-later-service" -publish = false - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -axum = "0.7.2" -link-for-later = { path = "../link-for-later" } -mongodb = "2.8.0" -tokio = { version = "1", features = ["macros"] } -tower = "0.4.13" -tracing = { version = "0.1", features = ["log"] } -tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] } - diff --git a/link-for-later-shuttle/Cargo.toml b/link-for-later-shuttle/Cargo.toml index e0d7a1b..71182ce 100644 --- a/link-for-later-shuttle/Cargo.toml +++ b/link-for-later-shuttle/Cargo.toml @@ -15,3 +15,4 @@ shuttle-runtime = "0.35.0" shuttle-shared-db = { version = "0.35.0", features = ["mongodb"] } tokio = { version = "1", features = ["macros"] } tracing = { version = "0.1", features = ["log"] } +tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] } diff --git a/link-for-later-shuttle/src/main.rs b/link-for-later-shuttle/src/main.rs index 8529a1e..4925874 100644 --- a/link-for-later-shuttle/src/main.rs +++ b/link-for-later-shuttle/src/main.rs @@ -2,6 +2,12 @@ use mongodb::Database; #[shuttle_runtime::main] async fn main(#[shuttle_shared_db::MongoDb] db: Database) -> shuttle_axum::ShuttleAxum { + tracing_subscriber::fmt() + .with_max_level(tracing::Level::DEBUG) + .with_target(false) + .without_time() + .init(); + let app = link_for_later::app::new(link_for_later::DatabaseType::MongoDb(db)); Ok(app.into()) } diff --git a/link-for-later/Cargo.toml b/link-for-later/Cargo.toml index 301df1f..3ee6637 100644 --- a/link-for-later/Cargo.toml +++ b/link-for-later/Cargo.toml @@ -6,6 +6,10 @@ description = "Link for Later Service" repository = "https://github.com/kentSarmiento/link-for-later-service" publish = false +[[bin]] +name = "link-for-later" +path = "src/bin/main.rs" + [dependencies] argon2 = "0.5.2" axum = "0.7.2" @@ -21,11 +25,11 @@ serde_json = "1.0.108" tokio = { version = "1", features = ["macros"] } tower = "0.4.13" tracing = { version = "0.1", features = ["log"] } +tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] } validator = { version = "0.16.1", features = ["derive"] } [dev-dependencies] mockall = "0.12.0" rand = "0.8.5" rstest = "0.18.2" -tracing-test = "0.2.4" diff --git a/link-for-later-axum/README.md b/link-for-later/src/bin/README.md similarity index 73% rename from link-for-later-axum/README.md rename to link-for-later/src/bin/README.md index 137666a..07445f4 100644 --- a/link-for-later-axum/README.md +++ b/link-for-later/src/bin/README.md @@ -7,13 +7,13 @@ For local development, a standalone server using axum can be used with either an * To use In-memory database, set `INMEMORY_DB` before running the server ```sh - INMEMORY_DB=true cargo run --bin link-for-later-axum + INMEMORY_DB=true cargo run --bin link-for-later ``` * To use MongoDb, set the MongoDB server and database name before running the server ```sh - MONGODB_URI="mongodb://localhost:23288" MONGODB_DATABASE_NAME="test" cargo run --bin link-for-later-axum + MONGODB_URI="mongodb://localhost:27017" MONGODB_DATABASE_NAME="test" cargo run --bin link-for-later ``` You will be able to send requests to the server using port 8080. diff --git a/link-for-later-axum/src/main.rs b/link-for-later/src/bin/main.rs similarity index 86% rename from link-for-later-axum/src/main.rs rename to link-for-later/src/bin/main.rs index 83614d4..c2ebe28 100644 --- a/link-for-later-axum/src/main.rs +++ b/link-for-later/src/bin/main.rs @@ -8,10 +8,7 @@ const MONGODB_DATABASE_NAME_KEY: &str = "MONGODB_DATABASE_NAME"; async fn main() -> Result<(), Box> { tracing_subscriber::fmt() .with_max_level(tracing::Level::DEBUG) - // disable printing the name of the module in every log line. .with_target(false) - // disabling time is handy because CloudWatch will add the ingestion time. - .without_time() .init(); let app = if std::env::var(INMEMORY_DB_KEY).is_ok() { diff --git a/link-for-later/src/controller/routes/links.rs b/link-for-later/src/controller/routes/links.rs index a9257cb..49881b2 100644 --- a/link-for-later/src/controller/routes/links.rs +++ b/link-for-later/src/controller/routes/links.rs @@ -134,7 +134,6 @@ mod tests { use axum::{extract::State, http::StatusCode}; use http_body_util::BodyExt; use serde_json::json; - use tracing_test::traced_test; use crate::{ entity::LinkItem, @@ -147,7 +146,6 @@ mod tests { use super::*; - #[traced_test] #[tokio::test] async fn test_get_links_empty() { let repo_query = LinkQueryBuilder::default().owner("user-id").build(); @@ -169,7 +167,6 @@ mod tests { assert_eq!(&body[..], b"[]"); } - #[traced_test] #[tokio::test] async fn test_get_links_non_empty() { let repo_query = LinkQueryBuilder::default().owner("user-id").build(); @@ -199,7 +196,6 @@ mod tests { assert!(body[0].url() == "http://link"); } - #[traced_test] #[tokio::test] async fn test_get_links_service_error() { let repo_query = LinkQueryBuilder::default().owner("user-id").build(); @@ -222,7 +218,6 @@ mod tests { assert_eq!(body, json!({"error": "test error"}).to_string()); } - #[traced_test] #[tokio::test] async fn test_post_link() { let request = LinkItemRequest::new("http://link"); @@ -258,7 +253,6 @@ mod tests { assert!(body.url() == "http://link"); } - #[traced_test] #[tokio::test] async fn test_post_link_invalid_url() { let request = LinkItemRequest::new("invalid-link"); @@ -282,7 +276,6 @@ mod tests { assert_eq!(body, json!({"error": "invalid request"}).to_string()); } - #[traced_test] #[tokio::test] async fn test_post_link_service_error() { let request = LinkItemRequest::new("http://link"); @@ -311,7 +304,6 @@ mod tests { assert_eq!(body, json!({"error": "test error"}).to_string()); } - #[traced_test] #[tokio::test] async fn test_get_link() { let repo_query = LinkQueryBuilder::new("1", "user-id").build(); @@ -346,7 +338,6 @@ mod tests { assert!(body.url() == "http://link"); } - #[traced_test] #[tokio::test] async fn test_get_link_service_error() { let repo_query = LinkQueryBuilder::new("1", "user-id").build(); @@ -374,7 +365,6 @@ mod tests { assert_eq!(body, json!({"error": "test error"}).to_string()); } - #[traced_test] #[tokio::test] async fn test_put_link() { let request = LinkItemRequest::new("http://link"); @@ -414,7 +404,6 @@ mod tests { assert!(body.url() == "http://link"); } - #[traced_test] #[tokio::test] async fn test_put_link_invalid_url() { let request = LinkItemRequest::new("invalid-link"); @@ -439,7 +428,6 @@ mod tests { assert_eq!(body, json!({"error": "invalid request"}).to_string()); } - #[traced_test] #[tokio::test] async fn test_put_link_service_error() { let request = LinkItemRequest::new("http://link"); @@ -472,7 +460,6 @@ mod tests { assert_eq!(body, json!({"error": "test error"}).to_string()); } - #[traced_test] #[tokio::test] async fn test_delete_link() { let item_to_delete = LinkItemBuilder::default().id("1").owner("user-id").build(); @@ -496,7 +483,6 @@ mod tests { assert_eq!(StatusCode::NO_CONTENT, parts.status); } - #[traced_test] #[tokio::test] async fn test_delete_link_service_error() { let item_to_delete = LinkItemBuilder::default().id("1").owner("user-id").build(); diff --git a/link-for-later/src/controller/routes/users.rs b/link-for-later/src/controller/routes/users.rs index e7346ba..bd9f0ff 100644 --- a/link-for-later/src/controller/routes/users.rs +++ b/link-for-later/src/controller/routes/users.rs @@ -76,7 +76,6 @@ mod tests { use http_body_util::BodyExt; use serde_json::json; - use tracing_test::traced_test; use crate::{ dto::Token, @@ -89,7 +88,6 @@ mod tests { use super::*; - #[traced_test] #[tokio::test] async fn test_register_user() { let request = UserInfoRequest::new("user@test.com", "test"); @@ -113,7 +111,6 @@ mod tests { assert_eq!(&body[..], b""); } - #[traced_test] #[tokio::test] async fn test_register_user_invalid_email() { let request = UserInfoRequest::new("user", "test"); @@ -132,7 +129,6 @@ mod tests { assert_eq!(body, json!({"error": "invalid request"}).to_string()); } - #[traced_test] #[tokio::test] async fn test_register_user_service_error() { let request = UserInfoRequest::new("user@test.com", "test"); @@ -156,7 +152,6 @@ mod tests { assert_eq!(body, json!({"error": "test error"}).to_string()); } - #[traced_test] #[tokio::test] async fn test_login_user() { let request = UserInfoRequest::new("user@test.com", "test"); @@ -181,7 +176,6 @@ mod tests { assert_eq!(body, json!({"token": "test"}).to_string()); } - #[traced_test] #[tokio::test] async fn test_login_user_invalid_email() { let request = UserInfoRequest::new("user", "test"); @@ -200,7 +194,6 @@ mod tests { assert_eq!(body, json!({"error": "invalid request"}).to_string()); } - #[traced_test] #[tokio::test] async fn test_login_user_service_error() { let request = UserInfoRequest::new("user@test.com", "test"); diff --git a/link-for-later/tests/app/mod.rs b/link-for-later/tests/app/mod.rs index bcd9779..dc61a23 100644 --- a/link-for-later/tests/app/mod.rs +++ b/link-for-later/tests/app/mod.rs @@ -3,6 +3,11 @@ use axum::Router; use crate::repository::{mongodb, DatabaseType}; pub async fn new(db_type: &DatabaseType) -> Router { + let _ = tracing_subscriber::fmt() + .with_max_level(tracing::Level::ERROR) + .with_target(false) + .try_init(); + match db_type { DatabaseType::InMemory => link_for_later::app::new(link_for_later::DatabaseType::InMemory), DatabaseType::MongoDb => { diff --git a/link-for-later/tests/links.rs b/link-for-later/tests/links.rs index 29e26f4..7e02cd9 100644 --- a/link-for-later/tests/links.rs +++ b/link-for-later/tests/links.rs @@ -8,7 +8,6 @@ use http_body_util::BodyExt; use rstest::rstest; use serde_json::json; use tower::ServiceExt; -use tracing_test::traced_test; use crate::{entity::LinkItem, repository::DatabaseType}; @@ -18,7 +17,6 @@ mod entity; mod repository; #[rstest] -#[traced_test] #[tokio::test] async fn test_get_links_empty( #[values(DatabaseType::InMemory, DatabaseType::MongoDb)] db_type: DatabaseType, @@ -47,7 +45,6 @@ async fn test_get_links_empty( } #[rstest] -#[traced_test] #[tokio::test] async fn test_get_links_non_empty(#[values(DatabaseType::MongoDb)] db_type: DatabaseType) { let repository = repository::new(&db_type); @@ -80,7 +77,6 @@ async fn test_get_links_non_empty(#[values(DatabaseType::MongoDb)] db_type: Data } #[rstest] -#[traced_test] #[tokio::test] async fn test_get_link_item_found(#[values(DatabaseType::MongoDb)] db_type: DatabaseType) { let repository = repository::new(&db_type); @@ -112,7 +108,6 @@ async fn test_get_link_item_found(#[values(DatabaseType::MongoDb)] db_type: Data } #[rstest] -#[traced_test] #[tokio::test] async fn test_get_link_item_not_found(#[values(DatabaseType::MongoDb)] db_type: DatabaseType) { let repository = repository::new(&db_type); @@ -141,7 +136,6 @@ async fn test_get_link_item_not_found(#[values(DatabaseType::MongoDb)] db_type: } #[rstest] -#[traced_test] #[tokio::test] async fn test_post_link(#[values(DatabaseType::MongoDb)] db_type: DatabaseType) { let repository = repository::new(&db_type); @@ -183,7 +177,6 @@ async fn test_post_link(#[values(DatabaseType::MongoDb)] db_type: DatabaseType) } #[rstest] -#[traced_test] #[tokio::test] async fn test_post_link_invalid_url(#[values(DatabaseType::MongoDb)] db_type: DatabaseType) { let repository = repository::new(&db_type); @@ -218,7 +211,6 @@ async fn test_post_link_invalid_url(#[values(DatabaseType::MongoDb)] db_type: Da } #[rstest] -#[traced_test] #[tokio::test] async fn test_put_link(#[values(DatabaseType::MongoDb)] db_type: DatabaseType) { let repository = repository::new(&db_type); @@ -263,7 +255,6 @@ async fn test_put_link(#[values(DatabaseType::MongoDb)] db_type: DatabaseType) { } #[rstest] -#[traced_test] #[tokio::test] async fn test_put_link_invalid_url(#[values(DatabaseType::MongoDb)] db_type: DatabaseType) { let repository = repository::new(&db_type); @@ -299,7 +290,6 @@ async fn test_put_link_invalid_url(#[values(DatabaseType::MongoDb)] db_type: Dat } #[rstest] -#[traced_test] #[tokio::test] async fn test_put_link_item_not_found(#[values(DatabaseType::MongoDb)] db_type: DatabaseType) { let repository = repository::new(&db_type); @@ -340,7 +330,6 @@ async fn test_put_link_item_not_found(#[values(DatabaseType::MongoDb)] db_type: } #[rstest] -#[traced_test] #[tokio::test] async fn test_delete_link(#[values(DatabaseType::MongoDb)] db_type: DatabaseType) { let repository = repository::new(&db_type); @@ -372,7 +361,6 @@ async fn test_delete_link(#[values(DatabaseType::MongoDb)] db_type: DatabaseType } #[rstest] -#[traced_test] #[tokio::test] async fn test_delete_link_item_not_found(#[values(DatabaseType::MongoDb)] db_type: DatabaseType) { let repository = repository::new(&db_type); @@ -410,7 +398,6 @@ async fn test_delete_link_item_not_found(#[values(DatabaseType::MongoDb)] db_typ } #[rstest] -#[traced_test] #[tokio::test] async fn test_unauthorized_access_to_links_no_token( #[values(DatabaseType::MongoDb)] db_type: DatabaseType, @@ -440,7 +427,6 @@ async fn test_unauthorized_access_to_links_no_token( } #[rstest] -#[traced_test] #[tokio::test] async fn test_unauthorized_access_to_links_invalid_token( #[values(DatabaseType::MongoDb)] db_type: DatabaseType, diff --git a/link-for-later/tests/users.rs b/link-for-later/tests/users.rs index 8a6bdc7..bd2120e 100644 --- a/link-for-later/tests/users.rs +++ b/link-for-later/tests/users.rs @@ -12,7 +12,6 @@ use http_body_util::BodyExt; use rstest::rstest; use serde_json::{json, Value}; use tower::ServiceExt; -use tracing_test::traced_test; use crate::repository::DatabaseType; @@ -22,7 +21,6 @@ mod entity; mod repository; #[rstest] -#[traced_test] #[tokio::test] async fn test_register_user(#[values(DatabaseType::MongoDb)] db_type: DatabaseType) { let repository = repository::new(&db_type); @@ -59,7 +57,6 @@ async fn test_register_user(#[values(DatabaseType::MongoDb)] db_type: DatabaseTy } #[rstest] -#[traced_test] #[tokio::test] async fn test_register_user_invalid_email(#[values(DatabaseType::MongoDb)] db_type: DatabaseType) { let repository = repository::new(&db_type); @@ -93,7 +90,6 @@ async fn test_register_user_invalid_email(#[values(DatabaseType::MongoDb)] db_ty } #[rstest] -#[traced_test] #[tokio::test] async fn test_register_user_already_registered( #[values(DatabaseType::MongoDb)] db_type: DatabaseType, @@ -133,7 +129,6 @@ async fn test_register_user_already_registered( } #[rstest] -#[traced_test] #[tokio::test] async fn test_login_user(#[values(DatabaseType::MongoDb)] db_type: DatabaseType) { let repository = repository::new(&db_type); @@ -171,7 +166,6 @@ async fn test_login_user(#[values(DatabaseType::MongoDb)] db_type: DatabaseType) } #[rstest] -#[traced_test] #[tokio::test] async fn test_login_user_invalid_email(#[values(DatabaseType::MongoDb)] db_type: DatabaseType) { repository::new(&db_type); @@ -202,7 +196,6 @@ async fn test_login_user_invalid_email(#[values(DatabaseType::MongoDb)] db_type: } #[rstest] -#[traced_test] #[tokio::test] async fn test_login_user_not_found(#[values(DatabaseType::MongoDb)] db_type: DatabaseType) { let repository = repository::new(&db_type); @@ -239,7 +232,6 @@ async fn test_login_user_not_found(#[values(DatabaseType::MongoDb)] db_type: Dat } #[rstest] -#[traced_test] #[tokio::test] async fn test_login_user_incorrect_password( #[values(DatabaseType::MongoDb)] db_type: DatabaseType,