From 7a9b7447577ed5eaeb326d1e9017a8f773e1f193 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Fri, 29 Jan 2021 21:11:07 +0100 Subject: add test for enforce_content_type --- src/request.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/request.rs b/src/request.rs index 8059e07..95f5a32 100644 --- a/src/request.rs +++ b/src/request.rs @@ -203,4 +203,25 @@ pub enum JsonError { #[error("json deserialize error: {0}")] Deserialize(#[from] serde_json::Error), +} + +#[cfg(test)] +mod tests { + use std::convert::TryInto; + + use hyper::{Request, header}; + + use super::SputnikParts; + + #[test] + fn test_enforce_content_type() { + let (mut parts, _body) = Request::new(hyper::Body::empty()).into_parts(); + assert!(parts.enforce_content_type(mime::APPLICATION_JSON).is_err()); + + parts.headers.append(header::CONTENT_TYPE, "application/json".try_into().unwrap()); + assert!(parts.enforce_content_type(mime::APPLICATION_JSON).is_ok()); + + parts.headers.insert(header::CONTENT_TYPE, "text/html".try_into().unwrap()); + assert!(parts.enforce_content_type(mime::APPLICATION_JSON).is_err()); + } } \ No newline at end of file -- cgit v1.2.3