1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-19 06:36:36 +00:00

add test for ClientRequestBuilder::form()

This commit is contained in:
Dursun Akkurt 2018-06-12 22:16:20 +03:00
parent 9cc7651c22
commit ffca416463

View file

@ -96,6 +96,35 @@ fn test_async_extractor_async() {
assert_eq!(bytes, Bytes::from_static(b"{\"test\":1}"));
}
#[derive(Deserialize)]
struct FormData {
username: String,
}
#[test]
fn test_form_extractor() {
let mut srv = test::TestServer::new(|app| {
app.resource("/{username}/index.html", |r| {
r.route().with(|form: Form<FormData>| {
Ok(format!("{}", form.username))
})
});
});
// client request
let request = srv
.post()
.uri(srv.url("/test1/index.html"))
.form(FormData{username: "test".into_string()})
.unwrap();
let response = srv.execute(request.send()).unwrap();
assert!(response.status().is_success());
// read response
let bytes = srv.execute(response.body()).unwrap();
assert_eq!(bytes, Bytes::from_static(b"test"));
}
#[test]
fn test_path_and_query_extractor() {
let mut srv = test::TestServer::new(|app| {