remove test load_stream and load_body

This commit is contained in:
Rob Ede 2021-12-14 22:18:23 +00:00
parent dd4a372613
commit 1d871fa187
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
4 changed files with 11 additions and 32 deletions

View File

@ -264,7 +264,7 @@ impl TestSeqBuffer {
/// Create new empty `TestBuffer` instance. /// Create new empty `TestBuffer` instance.
pub fn empty() -> Self { pub fn empty() -> Self {
Self::new("") Self::new(BytesMut::new())
} }
pub fn read_buf(&self) -> Ref<'_, BytesMut> { pub fn read_buf(&self) -> Ref<'_, BytesMut> {

View File

@ -37,9 +37,14 @@ extern crate tls_rustls as rustls;
use std::{fmt, net, thread, time::Duration}; use std::{fmt, net, thread, time::Duration};
use actix_codec::{AsyncRead, AsyncWrite, Framed}; use actix_codec::{AsyncRead, AsyncWrite, Framed};
pub use actix_http::test::TestBuffer; pub use actix_http::{body::to_bytes, test::TestBuffer};
use actix_http::{header::HeaderMap, ws, HttpService, Method, Request, Response}; use actix_http::{header::HeaderMap, ws, HttpService, Method, Request, Response};
pub use actix_http_test::unused_addr;
use actix_service::{map_config, IntoServiceFactory, ServiceFactory, ServiceFactoryExt as _}; use actix_service::{map_config, IntoServiceFactory, ServiceFactory, ServiceFactoryExt as _};
pub use actix_web::test::{
call_service, default_service, init_service, ok_service, read_body, read_body_json,
read_response, read_response_json, TestRequest,
};
use actix_web::{ use actix_web::{
body::MessageBody, body::MessageBody,
dev::{AppConfig, Server, ServerHandle, Service}, dev::{AppConfig, Server, ServerHandle, Service},
@ -48,12 +53,6 @@ use actix_web::{
}; };
use awc::{error::PayloadError, Client, ClientRequest, ClientResponse, Connector}; use awc::{error::PayloadError, Client, ClientRequest, ClientResponse, Connector};
use futures_core::Stream; use futures_core::Stream;
pub use actix_http_test::unused_addr;
pub use actix_web::test::{
call_service, default_service, init_service, load_stream, ok_service, read_body,
read_body_json, read_response, read_response_json, TestRequest,
};
use tokio::sync::mpsc; use tokio::sync::mpsc;
/// Start default [`TestServer`]. /// Start default [`TestServer`].

View File

@ -10,15 +10,13 @@ use actix_http::{
use actix_router::{Path, ResourceDef, Url}; use actix_router::{Path, ResourceDef, Url};
use actix_service::{IntoService, IntoServiceFactory, Service, ServiceFactory}; use actix_service::{IntoService, IntoServiceFactory, Service, ServiceFactory};
use actix_utils::future::{ok, poll_fn}; use actix_utils::future::{ok, poll_fn};
use futures_core::Stream;
use futures_util::StreamExt as _;
use serde::{de::DeserializeOwned, Serialize}; use serde::{de::DeserializeOwned, Serialize};
#[cfg(feature = "cookies")] #[cfg(feature = "cookies")]
use crate::cookie::{Cookie, CookieJar}; use crate::cookie::{Cookie, CookieJar};
use crate::{ use crate::{
app_service::AppInitServiceState, app_service::AppInitServiceState,
body::{self, BoxBody, MessageBody}, body::{BoxBody, MessageBody},
config::AppConfig, config::AppConfig,
data::Data, data::Data,
dev::Payload, dev::Payload,
@ -264,25 +262,6 @@ where
}) })
} }
pub async fn load_stream<S>(mut stream: S) -> Result<Bytes, Error>
where
S: Stream<Item = Result<Bytes, Error>> + Unpin,
{
let mut data = BytesMut::new();
while let Some(item) = stream.next().await {
data.extend_from_slice(&item?);
}
Ok(data.freeze())
}
pub async fn load_body<B>(body: B) -> Result<Bytes, Error>
where
B: MessageBody + Unpin,
B::Error: Into<Error>,
{
body::to_bytes(body).await.map_err(Into::into)
}
/// Helper function that returns a deserialized response body of a TestRequest /// Helper function that returns a deserialized response body of a TestRequest
/// ///
/// ``` /// ```

View File

@ -449,12 +449,13 @@ mod tests {
use super::*; use super::*;
use crate::{ use crate::{
body,
error::InternalError, error::InternalError,
http::{ http::{
header::{self, CONTENT_LENGTH, CONTENT_TYPE}, header::{self, CONTENT_LENGTH, CONTENT_TYPE},
StatusCode, StatusCode,
}, },
test::{assert_body_eq, load_body, TestRequest}, test::{assert_body_eq, TestRequest},
}; };
#[derive(Serialize, Deserialize, PartialEq, Debug)] #[derive(Serialize, Deserialize, PartialEq, Debug)]
@ -517,7 +518,7 @@ mod tests {
let resp = HttpResponse::from_error(s.err().unwrap()); let resp = HttpResponse::from_error(s.err().unwrap());
assert_eq!(resp.status(), StatusCode::BAD_REQUEST); assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
let body = load_body(resp.into_body()).await.unwrap(); let body = body::to_bytes(resp.into_body()).await.unwrap();
let msg: MyObject = serde_json::from_slice(&body).unwrap(); let msg: MyObject = serde_json::from_slice(&body).unwrap();
assert_eq!(msg.name, "invalid request"); assert_eq!(msg.name, "invalid request");
} }