mirror of https://github.com/fafhrd91/actix-web
add tests
This commit is contained in:
parent
ef829d78a1
commit
09f6497810
|
|
@ -3,6 +3,7 @@
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
- Minimum supported Rust version (MSRV) is now 1.83.
|
- Minimum supported Rust version (MSRV) is now 1.83.
|
||||||
|
- Add `MultipartForm` support for `Option<Vec<T>>` fields. [#3577]
|
||||||
|
|
||||||
## 0.7.2
|
## 0.7.2
|
||||||
|
|
||||||
|
|
@ -82,6 +83,7 @@
|
||||||
- `MultipartError` is now marked as non-exhaustive. [#2451]
|
- `MultipartError` is now marked as non-exhaustive. [#2451]
|
||||||
|
|
||||||
[#2451]: https://github.com/actix/actix-web/pull/2451
|
[#2451]: https://github.com/actix/actix-web/pull/2451
|
||||||
|
[#3577]: https://github.com/actix/actix-web/pull/3577
|
||||||
|
|
||||||
## 0.4.0-beta.7
|
## 0.4.0-beta.7
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -545,6 +545,40 @@ mod tests {
|
||||||
assert_eq!(response.status(), StatusCode::OK);
|
assert_eq!(response.status(), StatusCode::OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Test `Option<Vec>` fields.
|
||||||
|
#[derive(MultipartForm)]
|
||||||
|
struct TestOptionVec {
|
||||||
|
list1: Option<Vec<Text<String>>>,
|
||||||
|
list2: Option<Vec<Text<String>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn test_option_vec_route(form: MultipartForm<TestOptionVec>) -> impl Responder {
|
||||||
|
let form = form.into_inner();
|
||||||
|
let strings = form
|
||||||
|
.list1
|
||||||
|
.unwrap()
|
||||||
|
.into_iter()
|
||||||
|
.map(|s| s.into_inner())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
assert_eq!(strings, vec!["value1", "value2", "value3"]);
|
||||||
|
assert!(form.list2.is_none());
|
||||||
|
HttpResponse::Ok().finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn test_option_vec() {
|
||||||
|
let srv =
|
||||||
|
actix_test::start(|| App::new().route("/", web::post().to(test_option_vec_route)));
|
||||||
|
|
||||||
|
let mut form = multipart::Form::default();
|
||||||
|
form.add_text("list1", "value1");
|
||||||
|
form.add_text("list1", "value2");
|
||||||
|
form.add_text("list1", "value3");
|
||||||
|
|
||||||
|
let response = send_form(&srv, form, "/").await;
|
||||||
|
assert_eq!(response.status(), StatusCode::OK);
|
||||||
|
}
|
||||||
|
|
||||||
/// Test the `rename` field attribute.
|
/// Test the `rename` field attribute.
|
||||||
#[derive(MultipartForm)]
|
#[derive(MultipartForm)]
|
||||||
struct TestFieldRenaming {
|
struct TestFieldRenaming {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue