use actix_web::{web, HttpResponse, Responder}; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize, Debug)] struct AppState { count: i32, } #[allow(dead_code)] async fn index(data: web::Data) -> impl Responder { HttpResponse::Ok().json(data.get_ref()) } // #[cfg(test)] mod tests { use super::*; use actix_web::{test, web, App}; #[actix_rt::test] async fn test_index_get() { let mut app = test::init_service( App::new() .data(AppState { count: 4 }) .route("/", web::get().to(index)), ).await; let req = test::TestRequest::get().uri("/").to_request(); let resp: AppState = test::read_response_json(&mut app, req).await; assert_eq!(resp.count, 4); } } //