actix-web icon indicating copy to clipboard operation
actix-web copied to clipboard

multipart test utilities

Open robjtede opened this issue 2 years ago • 2 comments

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

robjtede avatar Jul 07 '22 18:07 robjtede

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);
    }

ThalisonCosta avatar Dec 11 '23 21:12 ThalisonCosta

started working on this in #3288

robjtede avatar Feb 13 '24 01:02 robjtede