1
0
mirror of https://github.com/actix/actix-website synced 2024-11-26 01:32:42 +01:00
actix-website/examples/testing/src/integration_two.rs

34 lines
799 B
Rust
Raw Normal View History

2019-06-24 23:43:31 +02:00
use actix_web::{web, HttpResponse, Responder};
use serde::{Deserialize, Serialize};
2019-06-17 21:39:58 +02:00
2019-06-24 23:43:31 +02:00
#[derive(Deserialize, Serialize, Debug)]
struct AppState {
count: i32,
}
2019-06-17 21:39:58 +02:00
2019-06-24 23:43:31 +02:00
#[allow(dead_code)]
fn index(data: web::Data<AppState>) -> impl Responder {
HttpResponse::Ok().json(data.get_ref())
}
2019-06-17 21:39:58 +02:00
2019-06-24 23:43:31 +02:00
// <integration-two>
#[cfg(test)]
mod tests {
use super::*;
use actix_web::{test, web, App};
2019-06-17 21:39:58 +02:00
2019-06-24 23:43:31 +02:00
#[test]
fn test_index_get() {
let mut app = test::init_service(
App::new()
.data(AppState { count: 4 })
.route("/", web::get().to(index)),
);
let req = test::TestRequest::get().uri("/").to_request();
let resp: AppState = test::read_response_json(&mut app, req);
2019-06-17 21:39:58 +02:00
2019-06-24 23:43:31 +02:00
assert!(resp.count == 4);
}
}
2019-06-17 21:39:58 +02:00
// </integration-two>