actix / actix-web

Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.
https://actix.rs
Apache License 2.0
21.4k stars 1.66k forks source link

multipart test utilities #2808

Open robjtede opened 2 years ago

robjtede commented 2 years ago

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

ThalisonCosta commented 9 months ago

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);
    }
robjtede commented 7 months ago

started working on this in #3288