fix failing tests

This commit is contained in:
ibraheemdev 2021-03-19 17:02:34 -04:00
parent ed33fcc0f7
commit 303b718c62
6 changed files with 27 additions and 10 deletions

View File

@ -1,18 +1,18 @@
//! Originally taken from `hyper::header::shared`.
mod charset;
mod content_encoding;
mod encoding;
mod entity;
mod extended;
mod httpdate;
mod quality_item;
mod content_encoding;
pub use self::charset::Charset;
pub use self::content_encoding::ContentEncoding;
pub use self::encoding::Encoding;
pub use self::entity::EntityTag;
pub use self::extended::{parse_extended_value, ExtendedValue};
pub use self::httpdate::HttpDate;
pub use self::quality_item::{q, qitem, Quality, QualityItem};
pub use self::content_encoding::ContentEncoding;
pub use language_tags::LanguageTag;

View File

@ -1133,7 +1133,7 @@ mod tests {
#[test]
fn response_builder_header_insert_typed() {
let mut res = Response::Ok();
res.insert_header(header::ContentType(mime::APPLICATION_OCTET_STREAM));
res.insert_header((header::CONTENT_TYPE, mime::APPLICATION_OCTET_STREAM));
let res = res.finish();
assert_eq!(
@ -1158,8 +1158,8 @@ mod tests {
#[test]
fn response_builder_header_append_typed() {
let mut res = Response::Ok();
res.append_header(header::ContentType(mime::APPLICATION_OCTET_STREAM));
res.append_header(header::ContentType(mime::APPLICATION_JSON));
res.append_header((header::CONTENT_TYPE, mime::APPLICATION_OCTET_STREAM));
res.append_header((header::CONTENT_TYPE, mime::APPLICATION_JSON));
let res = res.finish();
let headers: Vec<_> = res.headers().get_all("Content-Type").cloned().collect();

View File

@ -553,6 +553,8 @@ impl fmt::Debug for ClientRequest {
mod tests {
use std::time::SystemTime;
use actix_http::http::header::HttpDate;
use super::*;
use crate::Client;
@ -569,7 +571,7 @@ mod tests {
let req = Client::new()
.put("/")
.version(Version::HTTP_2)
.insert_header(header::Date(SystemTime::now().into()))
.insert_header((header::DATE, HttpDate::from(SystemTime::now())))
.content_type("plain/text")
.append_header((header::SERVER, "awc"));

View File

@ -1,7 +1,7 @@
//! Test helpers for actix http client to use during testing.
use std::convert::TryFrom;
use actix_http::http::header::{Header, IntoHeaderValue};
use actix_http::http::header::{Header, IntoHeaderPair, IntoHeaderValue};
use actix_http::http::{Error as HttpError, HeaderName, StatusCode, Version};
#[cfg(feature = "cookies")]
use actix_http::{
@ -58,6 +58,19 @@ impl TestResponse {
panic!("Can not set header");
}
// TODO: Should `set` be removed and replaced with this instead?
// It looks like `TestResponse` was missed in the header rework
pub fn insert_header<H>(mut self, header: H) -> Self
where
H: IntoHeaderPair,
{
if let Ok((key, value)) = header.try_into_header_pair() {
self.head.headers.insert(key, value);
return self;
}
panic!("Can not set header");
}
/// Append a header
pub fn header<K, V>(mut self, key: K, value: V) -> Self
where
@ -115,6 +128,8 @@ impl TestResponse {
mod tests {
use std::time::SystemTime;
use actix_http::http::header::HttpDate;
use super::*;
use crate::{cookie, http::header};
@ -122,7 +137,7 @@ mod tests {
fn test_basics() {
let res = TestResponse::default()
.version(Version::HTTP_2)
.set(header::Date(SystemTime::now().into()))
.insert_header((header::DATE, HttpDate::from(SystemTime::now())))
.cookie(cookie::Cookie::build("name", "value").finish())
.finish();
assert!(res.headers().contains_key(header::SET_COOKIE));

View File

@ -118,8 +118,8 @@ pub use crate::server::HttpServer;
pub use crate::types::{Either, EitherExtractError};
pub mod http {
pub use actix_http::http::*;
pub use crate::types::header;
pub use actix_http::http::*;
}
pub mod dev {

View File

@ -30,10 +30,10 @@ use crate::app_service::AppInitServiceState;
use crate::config::AppConfig;
use crate::data::Data;
use crate::dev::{Body, MessageBody, Payload, Server};
use crate::http::header::{ContentType, IntoHeaderPair};
use crate::rmap::ResourceMap;
use crate::service::{ServiceRequest, ServiceResponse};
use crate::{Error, HttpRequest, HttpResponse};
use crate::http::header::{ContentType, IntoHeaderPair};
/// Create service that always responds with `HttpResponse::Ok()`
pub fn ok_service(