aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-01-29 21:11:07 +0100
committerMartin Fischer <martin@push-f.com>2021-01-29 21:11:07 +0100
commit7a9b7447577ed5eaeb326d1e9017a8f773e1f193 (patch)
treeaf4ce23258ea3b09d24854ac8cf734f450f8dd3e
parentc7d3bd087c49bdd0b33ed23ff583bf58ba705a1c (diff)
add test for enforce_content_type
-rw-r--r--src/request.rs21
1 files changed, 21 insertions, 0 deletions
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