mirror of
https://github.com/LukeMathWalker/zero-to-production.git
synced 2024-11-27 19:41:08 +00:00
Update to latest version of actix-web, tracing-bunyan-formatter and tracing-subscriber. Use tokio macros instead of actix-web's macros.
This commit is contained in:
parent
5a99df9a18
commit
236564f954
7 changed files with 506 additions and 318 deletions
777
Cargo.lock
generated
777
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
14
Cargo.toml
14
Cargo.toml
|
@ -13,9 +13,8 @@ path = "src/main.rs"
|
||||||
name = "zero2prod"
|
name = "zero2prod"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-http = "=3.0.0-beta.10"
|
actix-web = "=4.0.0-beta.15"
|
||||||
actix-web = "=4.0.0-beta.9"
|
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
||||||
|
|
||||||
serde = "1.0.115"
|
serde = "1.0.115"
|
||||||
config = { version = "0.10.1", default-features = false, features = ["yaml"] }
|
config = { version = "0.10.1", default-features = false, features = ["yaml"] }
|
||||||
sqlx = { version = "0.5.1", default-features = false, features = [ "runtime-actix-rustls", "macros", "postgres", "uuid", "chrono", "migrate", "offline"] }
|
sqlx = { version = "0.5.1", default-features = false, features = [ "runtime-actix-rustls", "macros", "postgres", "uuid", "chrono", "migrate", "offline"] }
|
||||||
|
@ -25,16 +24,16 @@ reqwest = { version = "0.11", default-features = false, features = ["json", "rus
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
tracing = "0.1.19"
|
tracing = "0.1.19"
|
||||||
tracing-futures = "0.2.4"
|
tracing-futures = "0.2.4"
|
||||||
tracing-subscriber = { version = "0.2.12", features = ["registry", "env-filter"] }
|
tracing-subscriber = { version = "0.3", features = ["registry", "env-filter"] }
|
||||||
tracing-bunyan-formatter = "0.2.2"
|
tracing-bunyan-formatter = "0.3.1"
|
||||||
tracing-log = "0.1.1"
|
tracing-log = "0.1.1"
|
||||||
thiserror = "1.0.24"
|
thiserror = "1.0.24"
|
||||||
serde-aux = "1.0.1"
|
serde-aux = "1.0.1"
|
||||||
unicode-segmentation = "1.7.1"
|
unicode-segmentation = "1.7.1"
|
||||||
|
tracing-actix-web = "0.5.0-beta.6"
|
||||||
validator = "0.12.0"
|
validator = "0.12.0"
|
||||||
rand = { version = "0.8", features=["std_rng"] }
|
rand = { version = "0.8", features=["std_rng"] }
|
||||||
sha2 = { version = "0.9" }
|
sha2 = { version = "0.9" }
|
||||||
tracing-actix-web = "0.4.0-beta.12"
|
|
||||||
anyhow = "1.0.40"
|
anyhow = "1.0.40"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
@ -45,6 +44,5 @@ quickcheck_macros = "0.9.1"
|
||||||
fake = "~2.3.0"
|
fake = "~2.3.0"
|
||||||
wiremock = "0.5"
|
wiremock = "0.5"
|
||||||
serde_json = "1.0.61"
|
serde_json = "1.0.61"
|
||||||
actix-rt = "2"
|
reqwest = { version = "0.11", features = ["json"] }
|
||||||
tokio = { version = "1", features = ["macros"] }
|
|
||||||
linkify = "0.5.0"
|
linkify = "0.5.0"
|
||||||
|
|
|
@ -2,7 +2,7 @@ use zero2prod::configuration::get_configuration;
|
||||||
use zero2prod::startup::Application;
|
use zero2prod::startup::Application;
|
||||||
use zero2prod::telemetry::{get_subscriber, init_subscriber};
|
use zero2prod::telemetry::{get_subscriber, init_subscriber};
|
||||||
|
|
||||||
#[actix_web::main]
|
#[tokio::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
let subscriber = get_subscriber("zero2prod".into(), "info".into(), std::io::stdout);
|
let subscriber = get_subscriber("zero2prod".into(), "info".into(), std::io::stdout);
|
||||||
init_subscriber(subscriber);
|
init_subscriber(subscriber);
|
||||||
|
|
|
@ -11,11 +11,14 @@ use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
|
||||||
///
|
///
|
||||||
/// We are using `impl Subscriber` as return type to avoid having to spell out the actual
|
/// We are using `impl Subscriber` as return type to avoid having to spell out the actual
|
||||||
/// type of the returned subscriber, which is indeed quite complex.
|
/// type of the returned subscriber, which is indeed quite complex.
|
||||||
pub fn get_subscriber(
|
pub fn get_subscriber<Sink>(
|
||||||
name: String,
|
name: String,
|
||||||
env_filter: String,
|
env_filter: String,
|
||||||
sink: impl MakeWriter + Send + Sync + 'static,
|
sink: Sink,
|
||||||
) -> impl Subscriber + Sync + Send {
|
) -> impl Subscriber + Sync + Send
|
||||||
|
where
|
||||||
|
Sink: for<'a> MakeWriter<'a> + Send + Sync + 'static,
|
||||||
|
{
|
||||||
let env_filter =
|
let env_filter =
|
||||||
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(env_filter));
|
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(env_filter));
|
||||||
let formatting_layer = BunyanFormattingLayer::new(name, sink);
|
let formatting_layer = BunyanFormattingLayer::new(name, sink);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::helpers::spawn_app;
|
use crate::helpers::spawn_app;
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[tokio::test]
|
||||||
async fn health_check_works() {
|
async fn health_check_works() {
|
||||||
// Arrange
|
// Arrange
|
||||||
let app = spawn_app().await;
|
let app = spawn_app().await;
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::helpers::spawn_app;
|
||||||
use wiremock::matchers::{method, path};
|
use wiremock::matchers::{method, path};
|
||||||
use wiremock::{Mock, ResponseTemplate};
|
use wiremock::{Mock, ResponseTemplate};
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[tokio::test]
|
||||||
async fn subscribe_returns_a_200_for_valid_form_data() {
|
async fn subscribe_returns_a_200_for_valid_form_data() {
|
||||||
// Arrange
|
// Arrange
|
||||||
let app = spawn_app().await;
|
let app = spawn_app().await;
|
||||||
|
@ -21,7 +21,7 @@ async fn subscribe_returns_a_200_for_valid_form_data() {
|
||||||
assert_eq!(200, response.status().as_u16());
|
assert_eq!(200, response.status().as_u16());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[tokio::test]
|
||||||
async fn subscribe_persists_the_new_subscriber() {
|
async fn subscribe_persists_the_new_subscriber() {
|
||||||
// Arrange
|
// Arrange
|
||||||
let app = spawn_app().await;
|
let app = spawn_app().await;
|
||||||
|
@ -41,7 +41,7 @@ async fn subscribe_persists_the_new_subscriber() {
|
||||||
assert_eq!(saved.status, "pending_confirmation");
|
assert_eq!(saved.status, "pending_confirmation");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[tokio::test]
|
||||||
async fn subscribe_fails_if_there_is_a_fatal_database_error() {
|
async fn subscribe_fails_if_there_is_a_fatal_database_error() {
|
||||||
// Arrange
|
// Arrange
|
||||||
let app = spawn_app().await;
|
let app = spawn_app().await;
|
||||||
|
@ -59,7 +59,7 @@ async fn subscribe_fails_if_there_is_a_fatal_database_error() {
|
||||||
assert_eq!(response.status().as_u16(), 500);
|
assert_eq!(response.status().as_u16(), 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[tokio::test]
|
||||||
async fn subscribe_sends_a_confirmation_email_for_valid_data() {
|
async fn subscribe_sends_a_confirmation_email_for_valid_data() {
|
||||||
// Arrange
|
// Arrange
|
||||||
let app = spawn_app().await;
|
let app = spawn_app().await;
|
||||||
|
@ -79,7 +79,7 @@ async fn subscribe_sends_a_confirmation_email_for_valid_data() {
|
||||||
// Mock asserts on drop
|
// Mock asserts on drop
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[tokio::test]
|
||||||
async fn subscribe_sends_a_confirmation_email_with_a_link() {
|
async fn subscribe_sends_a_confirmation_email_with_a_link() {
|
||||||
// Arrange
|
// Arrange
|
||||||
let app = spawn_app().await;
|
let app = spawn_app().await;
|
||||||
|
@ -102,7 +102,7 @@ async fn subscribe_sends_a_confirmation_email_with_a_link() {
|
||||||
assert_eq!(confirmation_links.html, confirmation_links.plain_text);
|
assert_eq!(confirmation_links.html, confirmation_links.plain_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[tokio::test]
|
||||||
async fn subscribe_returns_a_400_when_data_is_missing() {
|
async fn subscribe_returns_a_400_when_data_is_missing() {
|
||||||
// Arrange
|
// Arrange
|
||||||
let app = spawn_app().await;
|
let app = spawn_app().await;
|
||||||
|
@ -127,7 +127,7 @@ async fn subscribe_returns_a_400_when_data_is_missing() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[tokio::test]
|
||||||
async fn subscribe_returns_a_400_when_fields_are_present_but_invalid() {
|
async fn subscribe_returns_a_400_when_fields_are_present_but_invalid() {
|
||||||
// Arrange
|
// Arrange
|
||||||
let app = spawn_app().await;
|
let app = spawn_app().await;
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::helpers::spawn_app;
|
||||||
use wiremock::matchers::{method, path};
|
use wiremock::matchers::{method, path};
|
||||||
use wiremock::{Mock, ResponseTemplate};
|
use wiremock::{Mock, ResponseTemplate};
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[tokio::test]
|
||||||
async fn confirmations_without_token_are_rejected_with_a_400() {
|
async fn confirmations_without_token_are_rejected_with_a_400() {
|
||||||
// Arrange
|
// Arrange
|
||||||
let app = spawn_app().await;
|
let app = spawn_app().await;
|
||||||
|
@ -16,7 +16,7 @@ async fn confirmations_without_token_are_rejected_with_a_400() {
|
||||||
assert_eq!(response.status().as_u16(), 400);
|
assert_eq!(response.status().as_u16(), 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[tokio::test]
|
||||||
async fn the_link_returned_by_subscribe_returns_a_200_if_called() {
|
async fn the_link_returned_by_subscribe_returns_a_200_if_called() {
|
||||||
// Arrange
|
// Arrange
|
||||||
let app = spawn_app().await;
|
let app = spawn_app().await;
|
||||||
|
@ -39,7 +39,7 @@ async fn the_link_returned_by_subscribe_returns_a_200_if_called() {
|
||||||
assert_eq!(response.status().as_u16(), 200);
|
assert_eq!(response.status().as_u16(), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[tokio::test]
|
||||||
async fn clicking_on_the_confirmation_link_confirms_a_subscriber() {
|
async fn clicking_on_the_confirmation_link_confirms_a_subscriber() {
|
||||||
// Arrange
|
// Arrange
|
||||||
let app = spawn_app().await;
|
let app = spawn_app().await;
|
||||||
|
|
Loading…
Reference in a new issue