actix-web
actix-web copied to clipboard
multipart test utilities
As for multipart testing api it should be something like
req.set_multipart(vec![ MultipartField::String("someField", "value whatever here") ]);
or just a MultipartForm object which is kind of like a map that you pass into set_multipart which sets all the required headers
- https://discord.com/channels/771444961383153695/993360047331606598/993362982627188757
Would be great to have this implemented on the actix-web testing api. For now, a solution is to use another crate actix-multipart-rfc7578. Actix also use this crate to test their own lib like on the following block of code
#[actix_rt::test]
async fn test_file_upload() {
let srv = actix_test::start(|| App::new().route("/", web::post().to(test_file_route)));
let mut form = multipart::Form::default();
let bytes = Cursor::new("Hello, world!");
form.add_reader_file_with_mime("file", bytes, "testfile.txt", mime::TEXT_PLAIN);
let response = send_form(&srv, form, "/").await;
assert_eq!(response.status(), StatusCode::OK);
}
started working on this in #3288