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:
Luca Palmieri 2021-12-26 16:28:03 +01:00
parent 06db310513
commit efce2d8ad4
7 changed files with 503 additions and 314 deletions

773
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -13,8 +13,8 @@ path = "src/main.rs"
name = "zero2prod"
[dependencies]
actix-http = "=3.0.0-beta.10"
actix-web = "=4.0.0-beta.9"
actix-web = "=4.0.0-beta.15"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
serde = "1.0.115"
config = { version = "0.10.1", default-features = false, features = ["yaml"] }
sqlx = { version = "0.5.5", default-features = false, features = [ "runtime-actix-rustls", "macros", "postgres", "uuid", "chrono", "migrate", "offline"] }
@ -24,15 +24,15 @@ reqwest = { version = "0.11", default-features = false, features = ["json", "rus
log = "0.4"
tracing = "0.1.19"
tracing-futures = "0.2.4"
tracing-subscriber = { version = "0.2.12", features = ["registry", "env-filter"] }
tracing-bunyan-formatter = "0.1.6"
tracing-subscriber = { version = "0.3", features = ["registry", "env-filter"] }
tracing-bunyan-formatter = "0.3.1"
tracing-log = "0.1.1"
serde-aux = "1.0.1"
unicode-segmentation = "1.7.1"
tracing-actix-web = "0.5.0-beta.6"
validator = "0.12.0"
rand = { version = "0.8", features=["std_rng"] }
sha2 = { version = "0.9" }
tracing-actix-web = "0.4.0-beta.12"
anyhow = "1.0.40"
[dev-dependencies]
@ -43,6 +43,5 @@ quickcheck_macros = "0.9.1"
fake = "~2.3.0"
wiremock = "0.5"
serde_json = "1.0.61"
actix-rt = "2"
tokio = { version = "1", features = ["macros"] }
reqwest = { version = "0.11", features = ["json"] }
linkify = "0.5.0"

View file

@ -2,7 +2,7 @@ use zero2prod::configuration::get_configuration;
use zero2prod::startup::Application;
use zero2prod::telemetry::{get_subscriber, init_subscriber};
#[actix_web::main]
#[tokio::main]
async fn main() -> std::io::Result<()> {
let subscriber = get_subscriber("zero2prod".into(), "info".into(), std::io::stdout);
init_subscriber(subscriber);

View file

@ -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
/// type of the returned subscriber, which is indeed quite complex.
pub fn get_subscriber(
pub fn get_subscriber<Sink>(
name: String,
env_filter: String,
sink: impl MakeWriter + Send + Sync + 'static,
) -> impl Subscriber + Sync + Send {
sink: Sink,
) -> impl Subscriber + Sync + Send
where
Sink: for<'a> MakeWriter<'a> + Send + Sync + 'static,
{
let env_filter =
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(env_filter));
let formatting_layer = BunyanFormattingLayer::new(name, sink);

View file

@ -1,6 +1,6 @@
use crate::helpers::spawn_app;
#[actix_rt::test]
#[tokio::test]
async fn health_check_works() {
// Arrange
let app = spawn_app().await;

View file

@ -2,7 +2,7 @@ use crate::helpers::spawn_app;
use wiremock::matchers::{method, path};
use wiremock::{Mock, ResponseTemplate};
#[actix_rt::test]
#[tokio::test]
async fn subscribe_returns_a_200_for_valid_form_data() {
// Arrange
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());
}
#[actix_rt::test]
#[tokio::test]
async fn subscribe_persists_the_new_subscriber() {
// Arrange
let app = spawn_app().await;
@ -41,7 +41,7 @@ async fn subscribe_persists_the_new_subscriber() {
assert_eq!(saved.status, "pending_confirmation");
}
#[actix_rt::test]
#[tokio::test]
async fn subscribe_sends_a_confirmation_email_for_valid_data() {
// Arrange
let app = spawn_app().await;
@ -61,7 +61,7 @@ async fn subscribe_sends_a_confirmation_email_for_valid_data() {
// Mock asserts on drop
}
#[actix_rt::test]
#[tokio::test]
async fn subscribe_sends_a_confirmation_email_with_a_link() {
// Arrange
let app = spawn_app().await;
@ -84,7 +84,7 @@ async fn subscribe_sends_a_confirmation_email_with_a_link() {
assert_eq!(confirmation_links.html, confirmation_links.plain_text);
}
#[actix_rt::test]
#[tokio::test]
async fn subscribe_returns_a_400_when_data_is_missing() {
// Arrange
let app = spawn_app().await;
@ -109,7 +109,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() {
// Arrange
let app = spawn_app().await;

View file

@ -2,7 +2,7 @@ use crate::helpers::spawn_app;
use wiremock::matchers::{method, path};
use wiremock::{Mock, ResponseTemplate};
#[actix_rt::test]
#[tokio::test]
async fn confirmations_without_token_are_rejected_with_a_400() {
// Arrange
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);
}
#[actix_rt::test]
#[tokio::test]
async fn the_link_returned_by_subscribe_returns_a_200_if_called() {
// Arrange
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);
}
#[actix_rt::test]
#[tokio::test]
async fn clicking_on_the_confirmation_link_confirms_a_subscriber() {
// Arrange
let app = spawn_app().await;