mirror of
https://github.com/actix/examples
synced 2025-02-02 17:39:05 +01:00
added unit test example to async_ex2
This commit is contained in:
parent
934d6e46f1
commit
4be1464249
@ -18,3 +18,4 @@ serde_json = "1.0.39"
|
|||||||
time = "0.1.42"
|
time = "0.1.42"
|
||||||
validator = "0.8.0"
|
validator = "0.8.0"
|
||||||
validator_derive = "0.8.0"
|
validator_derive = "0.8.0"
|
||||||
|
actix-service = "0.3.6"
|
||||||
|
@ -24,3 +24,34 @@ pub fn remove_product(id: web::Path<String>)
|
|||||||
-> impl Future<Item = HttpResponse, Error = Error> {
|
-> impl Future<Item = HttpResponse, Error = Error> {
|
||||||
fut_ok(HttpResponse::Ok().finish())
|
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