2017-05-25 05:45:03 +00:00
|
|
|
use std::fs::{self, File};
|
|
|
|
use std::io::prelude::*;
|
|
|
|
|
2017-06-06 20:41:04 +00:00
|
|
|
use rocket::local::Client;
|
2017-05-25 05:45:03 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_root() {
|
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:45:03 +00:00
|
|
|
|
|
|
|
// Check that we have exactly 25,000 'a'.
|
|
|
|
let res_str = res.body_string().unwrap();
|
|
|
|
assert_eq!(res_str.len(), 25000);
|
|
|
|
for byte in res_str.as_bytes() {
|
|
|
|
assert_eq!(*byte, b'a');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_file() {
|
|
|
|
// Create the 'big_file'
|
|
|
|
const CONTENTS: &str = "big_file contents...not so big here";
|
|
|
|
let mut file = File::create(super::FILENAME).expect("create big_file");
|
|
|
|
file.write_all(CONTENTS.as_bytes()).expect("write to big_file");
|
|
|
|
|
|
|
|
// Get the big file contents, hopefully.
|
2017-06-06 20:41:04 +00:00
|
|
|
let client = Client::new(super::rocket()).unwrap();
|
|
|
|
let mut res = client.get("/big_file").dispatch();
|
2017-05-25 05:45:03 +00:00
|
|
|
assert_eq!(res.body_string(), Some(CONTENTS.into()));
|
|
|
|
|
|
|
|
// Delete the 'big_file'.
|
|
|
|
fs::remove_file(super::FILENAME).expect("remove big_file");
|
|
|
|
}
|