mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-04-20 06:54:46 +00:00
openapi spec tests
This commit is contained in:
parent
81803fd54a
commit
e5e9cd5d3c
7 changed files with 431 additions and 9 deletions
|
@ -3,6 +3,8 @@ use gotham::{
|
|||
test::TestServer
|
||||
};
|
||||
use mime::Mime;
|
||||
#[allow(unused_imports)]
|
||||
use std::{fs::File, io::{Read, Write}, str};
|
||||
|
||||
pub fn test_get_response(server : &TestServer, path : &str, expected : &[u8])
|
||||
{
|
||||
|
@ -35,3 +37,21 @@ pub fn test_delete_response(server : &TestServer, path : &str, expected : &[u8])
|
|||
let body : &[u8] = res.as_ref();
|
||||
assert_eq!(body, expected);
|
||||
}
|
||||
|
||||
#[cfg(feature = "openapi")]
|
||||
pub fn test_openapi_response(server : &TestServer, path : &str, output_file : &str)
|
||||
{
|
||||
let res = server.client().get(path).perform().unwrap().read_body().unwrap();
|
||||
let body = serde_json::to_string_pretty(&serde_json::from_slice::<serde_json::Value>(res.as_ref()).unwrap()).unwrap();
|
||||
match File::open(output_file) {
|
||||
Ok(mut file) => {
|
||||
let mut expected = String::new();
|
||||
file.read_to_string(&mut expected).unwrap();
|
||||
assert_eq!(body, expected);
|
||||
},
|
||||
Err(_) => {
|
||||
let mut file = File::create(output_file).unwrap();
|
||||
file.write_all(body.as_bytes()).unwrap();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue