Add test utilities for server

This commit is contained in:
Lucien Greathouse 2018-06-05 23:18:33 -07:00
parent 9e0e12358c
commit 27d5bd3d6f
2 changed files with 26 additions and 16 deletions

View file

@ -4,30 +4,18 @@ extern crate serde;
extern crate librojo;
mod test_util;
use test_util::*;
use std::collections::HashMap;
use std::path::PathBuf;
use rouille::Request;
use librojo::{
session::Session,
project::Project,
web::{Server, WebConfig, ServerInfoResponse},
};
fn get(server: &Server, url: &str) -> String {
let info_request = Request::fake_http("GET", url, vec![], vec![]);
let response = server.handle_request(&info_request);
assert_eq!(response.status_code, 200);
let (mut reader, _) = response.data.into_reader_and_size();
let mut body = String::new();
reader.read_to_string(&mut body).unwrap();
body
}
#[test]
fn empty() {
let project_path = {
@ -44,7 +32,7 @@ fn empty() {
let server = Server::new(web_config);
{
let body = get(&server, "/api/rojo");
let body = server.get_string("/api/rojo");
let response = serde_json::from_str::<ServerInfoResponse>(&body).unwrap();
assert_eq!(response.server_id, "0");