fix doc tests

This commit is contained in:
Rob Ede 2021-06-05 07:04:13 +01:00
parent f319f52832
commit 3e049171eb
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
6 changed files with 14 additions and 12 deletions

View File

@ -141,7 +141,7 @@ impl From<&HandshakeError> for Response<AnyBody> {
impl From<HandshakeError> for Response<AnyBody> {
fn from(err: HandshakeError) -> Self {
err.into()
(&err).into()
}
}

View File

@ -417,7 +417,10 @@ async fn test_h2_response_http_error_handling() {
// read response
let bytes = srv.load_body(response).await.unwrap();
assert_eq!(bytes, Bytes::from_static(b"failed to parse header value"));
assert_eq!(
bytes,
Bytes::from_static(b"error processing HTTP: failed to parse header value")
);
}
#[derive(Debug, Display, Error)]
@ -426,7 +429,7 @@ struct BadRequest;
impl From<BadRequest> for Response<AnyBody> {
fn from(_: BadRequest) -> Self {
Response::bad_request()
Response::bad_request().set_body(AnyBody::from("error"))
}
}

View File

@ -91,7 +91,7 @@ async fn test_expect_continue() {
let _ = stream.write_all(b"GET /test HTTP/1.1\r\nexpect: 100-continue\r\n\r\n");
let mut data = String::new();
let _ = stream.read_to_string(&mut data);
assert!(data.starts_with("HTTP/1.1 412 Expectation Failed\r\ncontent-length"));
assert!(data.starts_with("HTTP/1.1 417 Expectation Failed\r\ncontent-length"));
let mut stream = net::TcpStream::connect(srv.addr()).unwrap();
let _ = stream.write_all(b"GET /test?yes= HTTP/1.1\r\nexpect: 100-continue\r\n\r\n");
@ -122,7 +122,7 @@ async fn test_expect_continue_h1() {
let _ = stream.write_all(b"GET /test HTTP/1.1\r\nexpect: 100-continue\r\n\r\n");
let mut data = String::new();
let _ = stream.read_to_string(&mut data);
assert!(data.starts_with("HTTP/1.1 412 Precondition Failed\r\ncontent-length"));
assert!(data.starts_with("HTTP/1.1 417 Expectation Failed\r\ncontent-length"));
let mut stream = net::TcpStream::connect(srv.addr()).unwrap();
let _ = stream.write_all(b"GET /test?yes= HTTP/1.1\r\nexpect: 100-continue\r\n\r\n");
@ -657,7 +657,7 @@ async fn test_h1_response_http_error_handling() {
// read response
let bytes = srv.load_body(response).await.unwrap();
assert_eq!(bytes, Bytes::from_static(b"failed to parse header value"));
assert_eq!(bytes, Bytes::from_static(b"error processing HTTP: failed to parse header value"));
}
#[derive(Debug, Display, Error)]
@ -666,7 +666,7 @@ struct BadRequest;
impl From<BadRequest> for Response<AnyBody> {
fn from(_: BadRequest) -> Self {
Response::bad_request()
Response::bad_request().set_body(AnyBody::from("error"))
}
}

View File

@ -19,7 +19,7 @@ pub use self::response_error::{Error, ResponseError};
/// A convenience [`Result`](std::result::Result) for Actix Web operations.
///
/// This type alias is generally used to avoid writing out `actix_http::Error` directly.
pub type Result<T, E = actix_http::Error> = std::result::Result<T, E>;
pub type Result<T, E = Error> = std::result::Result<T, E>;
/// Errors which can occur when attempting to generate resource uri.
#[derive(Debug, PartialEq, Display, Error, From)]

View File

@ -7,7 +7,7 @@ use std::{
use actix_http::{
http::{HeaderMap, Method, Uri, Version},
Error, Extensions, HttpMessage, Message, Payload, RequestHead,
Extensions, HttpMessage, Message, Payload, RequestHead,
};
use actix_router::{Path, Url};
use actix_utils::future::{ok, Ready};
@ -17,7 +17,7 @@ use smallvec::SmallVec;
use crate::{
app_service::AppInitServiceState, config::AppConfig, error::UrlGenerationError,
extract::FromRequest, info::ConnectionInfo, rmap::ResourceMap,
info::ConnectionInfo, rmap::ResourceMap, Error, FromRequest,
};
#[cfg(feature = "cookies")]

View File

@ -188,8 +188,7 @@ impl Route {
#[cfg(test)]
mod tests {
use std::convert::Infallible;
use std::time::Duration;
use std::{convert::Infallible, time::Duration};
use actix_rt::time::sleep;
use bytes::Bytes;