reinstate some tests

This commit is contained in:
Rob Ede 2021-12-04 04:30:08 +00:00
parent 1008598880
commit 450882ef30
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
1 changed files with 42 additions and 36 deletions

View File

@ -252,10 +252,7 @@ where
fn respond_to(self, req: &HttpRequest) -> HttpResponse<Self::Body> {
let headers = match self.headers {
Ok(headers) => headers,
Err(err) => {
return HttpResponse::from_error(err)
.map_body(|_, body| EitherBody::right(body))
}
Err(err) => return HttpResponse::from_error(err).map_into_right_body(),
};
let mut res = self.responder.respond_to(req);
@ -344,41 +341,50 @@ pub(crate) mod tests {
Bytes::from_static(b"test"),
);
// let res = (&"test".to_string()).respond_to(&req);
// assert_eq!(res.status(), StatusCode::OK);
// assert_eq!(
// res.headers().get(CONTENT_TYPE).unwrap(),
// HeaderValue::from_static("text/plain; charset=utf-8")
// );
// assert_eq!(
// to_bytes(res.into_body()).await.unwrap(),
// Bytes::from_static(b"test"),
// );
let res = (&"test".to_string()).respond_to(&req);
assert_eq!(res.status(), StatusCode::OK);
assert_eq!(
res.headers().get(CONTENT_TYPE).unwrap(),
HeaderValue::from_static("text/plain; charset=utf-8")
);
assert_eq!(
to_bytes(res.into_body()).await.unwrap(),
Bytes::from_static(b"test"),
);
// let s = String::from("test");
// let res = Cow::Borrowed(s.as_str()).respond_to(&req);
// assert_eq!(res.status(), StatusCode::OK);
// assert_eq!(res.body().bin_ref(), b"test");
// assert_eq!(
// res.headers().get(CONTENT_TYPE).unwrap(),
// HeaderValue::from_static("text/plain; charset=utf-8")
// );
let s = String::from("test");
let res = Cow::Borrowed(s.as_str()).respond_to(&req);
assert_eq!(res.status(), StatusCode::OK);
assert_eq!(
res.headers().get(CONTENT_TYPE).unwrap(),
HeaderValue::from_static("text/plain; charset=utf-8")
);
assert_eq!(
to_bytes(res.into_body()).await.unwrap(),
Bytes::from_static(b"test"),
);
// let res = Cow::<'_, str>::Owned(s).respond_to(&req);
// assert_eq!(res.status(), StatusCode::OK);
// assert_eq!(res.body().bin_ref(), b"test");
// assert_eq!(
// res.headers().get(CONTENT_TYPE).unwrap(),
// HeaderValue::from_static("text/plain; charset=utf-8")
// );
let res = Cow::<'_, str>::Owned(s).respond_to(&req);
assert_eq!(res.status(), StatusCode::OK);
assert_eq!(
res.headers().get(CONTENT_TYPE).unwrap(),
HeaderValue::from_static("text/plain; charset=utf-8")
);
assert_eq!(
to_bytes(res.into_body()).await.unwrap(),
Bytes::from_static(b"test"),
);
// let res = Cow::Borrowed("test").respond_to(&req);
// assert_eq!(res.status(), StatusCode::OK);
// assert_eq!(res.body().bin_ref(), b"test");
// assert_eq!(
// res.headers().get(CONTENT_TYPE).unwrap(),
// HeaderValue::from_static("text/plain; charset=utf-8")
// );
let res = Cow::Borrowed("test").respond_to(&req);
assert_eq!(res.status(), StatusCode::OK);
assert_eq!(
res.headers().get(CONTENT_TYPE).unwrap(),
HeaderValue::from_static("text/plain; charset=utf-8")
);
assert_eq!(
to_bytes(res.into_body()).await.unwrap(),
Bytes::from_static(b"test"),
);
let res = Bytes::from_static(b"test").respond_to(&req);
assert_eq!(res.status(), StatusCode::OK);