1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-04-20 06:54:46 +00:00

improve test coverage for the result types

This commit is contained in:
Dominic 2020-05-03 18:48:55 +02:00
parent 0d95ca4abb
commit 101e94b900
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
6 changed files with 171 additions and 84 deletions

View file

@ -10,10 +10,11 @@ use mime::Mime;
use openapiv3::{SchemaKind, StringFormat, StringType, Type, VariantOrUnknownOrEmpty};
use serde_json::error::Error as SerdeJsonError;
use std::{
fmt::{Debug, Display},
fmt::Display,
pin::Pin
};
#[derive(Debug)]
pub struct Raw<T>
{
pub raw : T,
@ -39,13 +40,6 @@ impl<T : Clone> Clone for Raw<T>
}
}
impl<T : Debug> Debug for Raw<T>
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Raw({:?}, {:?})", self.raw, self.mime)
}
}
impl<T : Into<Body>> ResourceResult for Raw<T>
where
Self : Send
@ -87,4 +81,24 @@ where
{
<Raw<T> as ResourceResult>::schema()
}
}
}
#[cfg(test)]
mod test
{
use super::*;
use futures_executor::block_on;
use mime::TEXT_PLAIN;
#[test]
fn raw_response()
{
let msg = "Test";
let raw = Raw::new(msg, TEXT_PLAIN);
let res = block_on(raw.into_response()).expect("didn't expect error response");
assert_eq!(res.status, StatusCode::OK);
assert_eq!(res.mime, Some(TEXT_PLAIN));
assert_eq!(res.full_body().unwrap(), msg.as_bytes());
}
}