#builder #multipart-form #forms #data #actix #multipart

actix-multipart-test

A simple actix multipart form data builder

3 releases

0.0.3 Jan 11, 2024
0.0.2 Nov 21, 2023
0.0.1 Nov 21, 2023

#11 in #form

Download history 86/week @ 2024-07-19 33/week @ 2024-07-26 3/week @ 2024-08-02 12/week @ 2024-08-09 61/week @ 2024-08-16 12/week @ 2024-08-23 74/week @ 2024-08-30 30/week @ 2024-09-06 76/week @ 2024-09-13 101/week @ 2024-09-20 134/week @ 2024-09-27 135/week @ 2024-10-04 115/week @ 2024-10-11 154/week @ 2024-10-18 113/week @ 2024-10-25 35/week @ 2024-11-01

454 downloads per month

Apache-2.0

58KB
91 lines

Actix Multipart Form Data For Testing

This is a simple example of how to test multipart form data with actix-web endpoints.

Usage

#[cfg(test)]
mod tests {

    use actix_multipart_test::MultiPartFormDataBuilder;
    use actix_web::{test, App};
    use super::*;

    #[actix_web::test]
    async fn test_should_upload_file() {
        
        let mut app =
            test::init_service(
                    App::new()
                    .service(yourmultipartformhandler)
                )
                .await;

        let mut multipart_form_data_builder = MultiPartFormDataBuilder::new();
        multipart_form_data_builder.with_file("tests/sample.png", "sample", "image/png", "sample.png");
        multipart_form_data_builder.with_text("name", "some_name");
        let (header, body) = multipart_form_data_builder.build();
        
        let req = test::TestRequest::post()
            .uri("/somerurl")
            .insert_header(header)
            .set_payload(body)
            .to_request();
        let resp = test::call_service(&mut app, req).await;

        assert!(resp.status().is_success());

    }
}

Dependencies

~225KB