You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.2 KiB
54 lines
1.2 KiB
use gotham::test::TestServer;
|
|
use hyper::StatusCode;
|
|
use lazy_static::lazy_static;
|
|
use tempfile::{tempdir, TempDir};
|
|
|
|
use crate::config::Config;
|
|
use crate::routes;
|
|
|
|
lazy_static! {
|
|
static ref TEMPDIR: TempDir = tempdir().unwrap();
|
|
static ref CONFIG: Config = {
|
|
let mut c: Config = Default::default();
|
|
c.data_directory = TEMPDIR.path().into();
|
|
c
|
|
};
|
|
static ref TEST_SERVER: TestServer = TestServer::new(routes::build(CONFIG.clone())).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn get_index() {
|
|
let res = TEST_SERVER.client().get(&CONFIG.url).perform().unwrap();
|
|
assert_eq!(res.status(), StatusCode::OK);
|
|
}
|
|
|
|
#[test]
|
|
fn submit_html() {
|
|
let res = TEST_SERVER
|
|
.client()
|
|
.post(
|
|
&CONFIG.url,
|
|
"paste=test",
|
|
mime::APPLICATION_WWW_FORM_URLENCODED,
|
|
)
|
|
.perform()
|
|
.unwrap();
|
|
assert_eq!(res.status(), StatusCode::SEE_OTHER);
|
|
}
|
|
|
|
#[test]
|
|
fn submit_text_and_check_raw() {
|
|
let res = TEST_SERVER
|
|
.client()
|
|
.put(&CONFIG.url, "test", mime::TEXT_PLAIN)
|
|
.perform()
|
|
.unwrap();
|
|
assert_eq!(res.status(), StatusCode::OK);
|
|
|
|
let redirect_url = res.read_utf8_body().unwrap();
|
|
let new_url = format!("{}/raw", redirect_url.trim_end());
|
|
let res = TEST_SERVER.client().get(new_url).perform().unwrap();
|
|
let body = res.read_utf8_body().unwrap();
|
|
assert_eq!(body, "test");
|
|
}
|