mirror of
https://github.com/actix/examples
synced 2025-01-22 22:05:57 +01:00
Merge pull request #110 from Dowwie/master
added unit test example to async_ex2
This commit is contained in:
commit
173d65f285
@ -18,3 +18,4 @@ serde_json = "1.0.39"
|
||||
time = "0.1.42"
|
||||
validator = "0.8.0"
|
||||
validator_derive = "0.8.0"
|
||||
actix-service = "0.3.6"
|
||||
|
@ -23,4 +23,35 @@ pub fn get_product_detail(id: web::Path<String>)
|
||||
pub fn remove_product(id: web::Path<String>)
|
||||
-> impl Future<Item = HttpResponse, Error = Error> {
|
||||
fut_ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use actix_service::Service;
|
||||
use actix_web::{test, HttpResponse, HttpRequest, App,
|
||||
http::{header, StatusCode}, web};
|
||||
use crate::appconfig::config_app;
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_add_product() {
|
||||
let mut app = test::init_service(
|
||||
App::new()
|
||||
.configure(config_app)
|
||||
);
|
||||
|
||||
let payload = r#"{"id":12345,"product_type":"fancy","name":"test"}"#.as_bytes();
|
||||
|
||||
let req = test::TestRequest::post()
|
||||
.uri("/products")
|
||||
.header(header::CONTENT_TYPE, "application/json")
|
||||
.set_payload(payload)
|
||||
.to_request();
|
||||
|
||||
let resp = test::block_on(app.call(req)).unwrap();
|
||||
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user