1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-04-20 23:07:01 +00:00

attempt testing (doesn't work)

This commit is contained in:
Dominic 2019-09-27 15:35:02 +02:00
parent 5ef80deecf
commit a42d9750ef
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
7 changed files with 540 additions and 46 deletions

66
tests/users.rs Normal file
View file

@ -0,0 +1,66 @@
#[macro_use]
extern crate serde_derive;
use fake::{faker::internet::en::Username, Fake};
use gotham::{
router::builder::build_simple_router,
state::State
};
use gotham_restful::{DrawResources, DrawResourceRoutes, IndexResource, Resource, ResourceResult, Success};
use reqwest;
use std::{
thread,
time::Duration
};
struct Users;
#[derive(Serialize)]
struct User
{
username : String
}
impl IndexResource<Success<Vec<User>>> for Users
{
fn index(state : &mut State) -> Success<Vec<User>>
{
panic!("Index handler called");
vec![Username().fake(), Username().fake()]
.into_iter()
.map(|username| User { username })
.collect::<Vec<User>>()
.into()
}
}
impl Resource for Users
{
fn setup<D : DrawResourceRoutes>(route : D)
{
}
}
const ADDR : &str = "127.0.0.1:18080";
pub fn setup()
{
thread::spawn(|| {
gotham::start(ADDR, build_simple_router(|route| {
route.resource::<Users, _>("users");
}));
panic!("Gotham started on {} for testing", ADDR);
});
thread::sleep(Duration::from_millis(1000));
}
#[test]
fn user_index()
{
setup();
let answer = reqwest::get(&format!("http://{}/users", ADDR))
.expect("Unable to execute GET request")
.text()
.expect("Unable to get body of GET request");
panic!("answer: {}", answer);
}