2017-06-06 20:41:04 +00:00
|
|
|
use rocket::local::Client;
|
2017-05-25 05:56:52 +00:00
|
|
|
use rocket::http::{Status, ContentType};
|
|
|
|
|
|
|
|
use std::io::Read;
|
2017-06-06 20:41:04 +00:00
|
|
|
use std::fs::{self, File};
|
|
|
|
|
|
|
|
const UPLOAD_CONTENTS: &str = "Hey! I'm going to be uploaded. :D Yay!";
|
2017-05-25 05:56:52 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_index() {
|
2017-06-06 20:41:04 +00:00
|
|
|
let client = Client::new(super::rocket()).unwrap();
|
|
|
|
let mut res = client.get("/").dispatch();
|
2017-05-25 05:56:52 +00:00
|
|
|
assert_eq!(res.body_string(), Some(super::index().to_string()));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_raw_upload() {
|
2017-06-06 20:41:04 +00:00
|
|
|
// Delete the upload file before we begin.
|
|
|
|
let _ = fs::remove_file("/tmp/upload.txt");
|
2017-05-25 05:56:52 +00:00
|
|
|
|
2017-06-06 20:41:04 +00:00
|
|
|
// Do the upload. Make sure we get the expected results.
|
|
|
|
let client = Client::new(super::rocket()).unwrap();
|
|
|
|
let mut res = client.post("/upload")
|
2017-05-25 05:56:52 +00:00
|
|
|
.header(ContentType::Plain)
|
2017-06-06 20:41:04 +00:00
|
|
|
.body(UPLOAD_CONTENTS)
|
|
|
|
.dispatch();
|
2017-05-25 05:56:52 +00:00
|
|
|
|
|
|
|
assert_eq!(res.status(), Status::Ok);
|
|
|
|
assert_eq!(res.body_string(), Some(UPLOAD_CONTENTS.len().to_string()));
|
|
|
|
|
|
|
|
// Ensure we find the body in the /tmp/upload.txt file.
|
|
|
|
let mut file_contents = String::new();
|
|
|
|
let mut file = File::open("/tmp/upload.txt").expect("open upload.txt file");
|
|
|
|
file.read_to_string(&mut file_contents).expect("read upload.txt");
|
|
|
|
assert_eq!(&file_contents, UPLOAD_CONTENTS);
|
|
|
|
}
|