mirror of https://github.com/rwf2/Rocket.git
Make 'cargo test' work without '--all-features'.
This commit is contained in:
parent
2da08a975c
commit
069f09cb7e
|
@ -4,7 +4,6 @@
|
|||
extern crate rocket;
|
||||
|
||||
use rocket::request::Form;
|
||||
use rocket::http::Status;
|
||||
|
||||
#[derive(FromForm)]
|
||||
struct FormData {
|
||||
|
@ -17,12 +16,15 @@ fn bug(form_data: Form<FormData>) -> &'static str {
|
|||
"OK"
|
||||
}
|
||||
|
||||
use rocket::testing::MockRequest;
|
||||
use rocket::http::Method::*;
|
||||
use rocket::http::ContentType;
|
||||
#[cfg(feature = "testing")]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use rocket::testing::MockRequest;
|
||||
use rocket::http::Method::*;
|
||||
use rocket::http::{Status, ContentType};
|
||||
|
||||
#[test]
|
||||
fn method_eval() {
|
||||
#[test]
|
||||
fn method_eval() {
|
||||
let rocket = rocket::ignite().mount("/", routes![bug]);
|
||||
|
||||
let mut req = MockRequest::new(Post, "/")
|
||||
|
@ -32,10 +34,10 @@ fn method_eval() {
|
|||
let mut response = req.dispatch_with(&rocket);
|
||||
let body_str = response.body().and_then(|b| b.into_string());
|
||||
assert_eq!(body_str, Some("OK".to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_passes_through() {
|
||||
#[test]
|
||||
fn get_passes_through() {
|
||||
let rocket = rocket::ignite().mount("/", routes![bug]);
|
||||
|
||||
let mut req = MockRequest::new(Get, "/")
|
||||
|
@ -44,4 +46,5 @@ fn get_passes_through() {
|
|||
|
||||
let response = req.dispatch_with(&rocket);
|
||||
assert_eq!(response.status(), Status::NotFound);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,12 +15,15 @@ fn bug(form_data: Form<FormData>) -> String {
|
|||
form_data.into_inner().form_data
|
||||
}
|
||||
|
||||
use rocket::testing::MockRequest;
|
||||
use rocket::http::Method::*;
|
||||
use rocket::http::ContentType;
|
||||
use rocket::http::Status;
|
||||
#[cfg(feature = "testing")]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use rocket::testing::MockRequest;
|
||||
use rocket::http::Method::*;
|
||||
use rocket::http::ContentType;
|
||||
use rocket::http::Status;
|
||||
|
||||
fn check_decoding(raw: &str, decoded: &str) {
|
||||
fn check_decoding(raw: &str, decoded: &str) {
|
||||
let rocket = rocket::ignite().mount("/", routes![bug]);
|
||||
|
||||
let mut req = MockRequest::new(Post, "/")
|
||||
|
@ -31,10 +34,10 @@ fn check_decoding(raw: &str, decoded: &str) {
|
|||
let body_string = response.body().and_then(|b| b.into_string());
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(Some(decoded.to_string()), body_string);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_proper_decoding() {
|
||||
#[test]
|
||||
fn test_proper_decoding() {
|
||||
check_decoding("password", "password");
|
||||
check_decoding("", "");
|
||||
check_decoding("+", " ");
|
||||
|
@ -42,4 +45,5 @@ fn test_proper_decoding() {
|
|||
check_decoding("1+1", "1 1");
|
||||
check_decoding("1%2B1", "1+1");
|
||||
check_decoding("%3Fa%3D1%26b%3D2", "?a=1&b=2");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
|
||||
extern crate rocket;
|
||||
|
||||
use rocket::Route;
|
||||
use rocket::response::{status, content};
|
||||
use rocket::http::ContentType;
|
||||
|
||||
#[get("/empty")]
|
||||
fn empty() -> status::NoContent {
|
||||
|
@ -22,17 +20,22 @@ fn other() -> content::JSON<()> {
|
|||
content::JSON(())
|
||||
}
|
||||
|
||||
fn routes() -> Vec<Route> {
|
||||
#[cfg(feature = "testing")]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use rocket::Route;
|
||||
use rocket::testing::MockRequest;
|
||||
use rocket::http::Method::*;
|
||||
use rocket::http::{Status, ContentType};
|
||||
use rocket::response::Body;
|
||||
|
||||
fn routes() -> Vec<Route> {
|
||||
routes![index, empty, other]
|
||||
}
|
||||
}
|
||||
|
||||
use rocket::testing::MockRequest;
|
||||
use rocket::http::Method::*;
|
||||
use rocket::http::Status;
|
||||
use rocket::response::Body;
|
||||
|
||||
#[test]
|
||||
fn auto_head() {
|
||||
#[test]
|
||||
fn auto_head() {
|
||||
let rocket = rocket::ignite().mount("/", routes());
|
||||
|
||||
let mut req = MockRequest::new(Head, "/");
|
||||
|
@ -57,10 +60,10 @@ fn auto_head() {
|
|||
let mut req = MockRequest::new(Head, "/empty");
|
||||
let response = req.dispatch_with(&rocket);
|
||||
assert_eq!(response.status(), Status::NoContent);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn user_head() {
|
||||
#[test]
|
||||
fn user_head() {
|
||||
let rocket = rocket::ignite().mount("/", routes());
|
||||
let mut req = MockRequest::new(Head, "/other");
|
||||
let response = req.dispatch_with(&rocket);
|
||||
|
@ -69,4 +72,5 @@ fn user_head() {
|
|||
|
||||
let content_type: Vec<_> = response.header_values("Content-Type").collect();
|
||||
assert_eq!(content_type, vec![ContentType::JSON.to_string()]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,11 +30,14 @@ fn dual(user: String, path: Segments) -> String {
|
|||
user + "/is/" + &path.collect::<Vec<_>>().join("/")
|
||||
}
|
||||
|
||||
use rocket::testing::MockRequest;
|
||||
use rocket::http::Method::*;
|
||||
#[cfg(feature = "testing")]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use rocket::testing::MockRequest;
|
||||
use rocket::http::Method::*;
|
||||
|
||||
#[test]
|
||||
fn segments_works() {
|
||||
#[test]
|
||||
fn segments_works() {
|
||||
let rocket = rocket::ignite()
|
||||
.mount("/", routes![test, two, one_two, none, dual])
|
||||
.mount("/point", routes![test, two, one_two, dual]);
|
||||
|
@ -52,4 +55,5 @@ fn segments_works() {
|
|||
let body_str = response.body().and_then(|b| b.into_string());
|
||||
assert_eq!(body_str, Some(path.into()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue