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

Replace methods with more flexible endpoints

This commit is contained in:
msrd0 2021-01-18 00:05:30 +00:00
parent 0ac0f0f504
commit b807ae2796
87 changed files with 1497 additions and 1512 deletions

View file

@ -2,12 +2,14 @@ use gotham::{
hyper::Body,
test::TestServer
};
use log::info;
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])
{
info!("GET {}", path);
let res = server.client().get(path).perform().unwrap().read_body().unwrap();
let body : &[u8] = res.as_ref();
assert_eq!(body, expected);
@ -17,6 +19,7 @@ pub fn test_post_response<B>(server : &TestServer, path : &str, body : B, mime :
where
B : Into<Body>
{
info!("POST {}", path);
let res = server.client().post(path, body, mime).perform().unwrap().read_body().unwrap();
let body : &[u8] = res.as_ref();
assert_eq!(body, expected);
@ -26,6 +29,7 @@ pub fn test_put_response<B>(server : &TestServer, path : &str, body : B, mime :
where
B : Into<Body>
{
info!("PUT {}", path);
let res = server.client().put(path, body, mime).perform().unwrap().read_body().unwrap();
let body : &[u8] = res.as_ref();
assert_eq!(body, expected);
@ -33,6 +37,7 @@ where
pub fn test_delete_response(server : &TestServer, path : &str, expected : &[u8])
{
info!("DELETE {}", path);
let res = server.client().delete(path).perform().unwrap().read_body().unwrap();
let body : &[u8] = res.as_ref();
assert_eq!(body, expected);
@ -41,12 +46,14 @@ pub fn test_delete_response(server : &TestServer, path : &str, expected : &[u8])
#[cfg(feature = "openapi")]
pub fn test_openapi_response(server : &TestServer, path : &str, output_file : &str)
{
info!("GET {}", path);
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();
eprintln!("{}", body);
assert_eq!(body, expected);
},
Err(_) => {