Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multipart test utilities #2808

Open
robjtede opened this issue Jul 7, 2022 · 2 comments
Open

multipart test utilities #2808

robjtede opened this issue Jul 7, 2022 · 2 comments
Labels
A-web project: actix-web C-feature Category: new functionality

Comments

@robjtede
Copy link
Member

robjtede commented Jul 7, 2022

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

@robjtede robjtede added C-feature Category: new functionality A-web project: actix-web labels Jul 7, 2022
@ThalisonCosta
Copy link

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
Copy link
Member Author

started working on this in #3288

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-web project: actix-web C-feature Category: new functionality
Projects
None yet
Development

No branches or pull requests

2 participants