pub struct MultiPartFormDataBuilder { /* private fields */ }Expand description
Simple builder for multipart/form-data test
Examples
#[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("/someurl")
.insert_header(header)
.set_payload(body)
.to_request();
let resp = test::call_service(&mut app, req).await;
assert!(resp.status().is_success());
}
}Implementations§
source§impl MultiPartFormDataBuilder
impl MultiPartFormDataBuilder
sourcepub fn new() -> MultiPartFormDataBuilder
pub fn new() -> MultiPartFormDataBuilder
Create new MultiPartFormDataBuilder
sourcepub fn with_text(
&mut self,
name: impl Into<String>,
value: impl Into<String>
) -> &mut MultiPartFormDataBuilder
pub fn with_text( &mut self, name: impl Into<String>, value: impl Into<String> ) -> &mut MultiPartFormDataBuilder
Add text to multipart/form-data
name is form name
value is form value
Returns &mut MultiPartFormDataBuilder
sourcepub fn with_file(
&mut self,
path: impl AsRef<Path> + 'static,
name: impl Into<String>,
content_type: impl Into<String>,
file_name: impl Into<String>
) -> &mut MultiPartFormDataBuilder
pub fn with_file( &mut self, path: impl AsRef<Path> + 'static, name: impl Into<String>, content_type: impl Into<String>, file_name: impl Into<String> ) -> &mut MultiPartFormDataBuilder
Add file to multipart/form-data
path is file path
name is form name
content_type is file content type
file_name is file name
Auto Trait Implementations§
impl !RefUnwindSafe for MultiPartFormDataBuilder
impl !Send for MultiPartFormDataBuilder
impl !Sync for MultiPartFormDataBuilder
impl Unpin for MultiPartFormDataBuilder
impl !UnwindSafe for MultiPartFormDataBuilder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more