From 55a25358960fc0c93f02a33da5af3c2a59c48bb5 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Wed, 28 Dec 2016 18:24:54 -0600 Subject: [PATCH] Clean up config example. --- examples/config/src/main.rs | 3 --- examples/config/src/tests.rs | 13 ------------- examples/config/tests/common/mod.rs | 11 ++++++----- examples/config/tests/development.rs | 5 ++--- examples/config/tests/production.rs | 5 ++--- examples/config/tests/staging.rs | 5 ++--- 6 files changed, 12 insertions(+), 30 deletions(-) delete mode 100644 examples/config/src/tests.rs diff --git a/examples/config/src/main.rs b/examples/config/src/main.rs index 30fb2b83..84583182 100644 --- a/examples/config/src/main.rs +++ b/examples/config/src/main.rs @@ -4,9 +4,6 @@ extern crate rocket; extern crate config; -#[cfg(test)] -mod tests; - // This example's illustration is the Rocket.toml file. fn main() { rocket::ignite().mount("/hello", routes![config::hello]).launch() diff --git a/examples/config/src/tests.rs b/examples/config/src/tests.rs deleted file mode 100644 index 7f8bc55a..00000000 --- a/examples/config/src/tests.rs +++ /dev/null @@ -1,13 +0,0 @@ -use super::rocket; -use rocket::testing::MockRequest; -use rocket::http::Method; - -#[test] -fn test_hello_world() { - let rocket = rocket::ignite().mount("/hello", routes![super::hello]); - let mut request = MockRequest::new(Method::Get, "/hello"); - let mut response = request.dispatch_with(&rocket); - - assert_eq!(response.body().and_then(|b| b.into_string()), - Some("Hello, world!".to_string())); -} diff --git a/examples/config/tests/common/mod.rs b/examples/config/tests/common/mod.rs index 375b22a1..3a248414 100644 --- a/examples/config/tests/common/mod.rs +++ b/examples/config/tests/common/mod.rs @@ -1,17 +1,18 @@ extern crate rocket; extern crate config as lib; -use std; + use rocket::config::{self, Environment}; use rocket::http::Method; use rocket::LoggingLevel; use rocket::testing::MockRequest; - pub fn test_config(environment: Environment) { - // Manually set the config environment variable so that Rocket initializes it in `init()`. - std::env::set_var("ROCKET_ENV", environment.to_string()); + // Manually set the config environment variable. Rocket will initialize the + // environment in `ignite()`. + ::std::env::set_var("ROCKET_ENV", environment.to_string()); rocket::ignite().mount("/hello", routes![lib::hello]); + // Get the active environment and ensure that it matches our expectations. let config = config::active().unwrap(); match environment { Environment::Development => { @@ -39,7 +40,7 @@ pub fn test_config(environment: Environment) { } } - // Rocket `take`s the key, so this should always be `None` + // Rocket `take`s the key, so this should always be `None`. assert_eq!(config.take_session_key(), None); } diff --git a/examples/config/tests/development.rs b/examples/config/tests/development.rs index df35d228..439aff73 100644 --- a/examples/config/tests/development.rs +++ b/examples/config/tests/development.rs @@ -2,12 +2,11 @@ #![plugin(rocket_codegen)] extern crate rocket; -use rocket::config::Environment; mod common; #[test] -fn test() { - common::test_config(Environment::Development); +fn test_development_config() { + common::test_config(rocket::config::Environment::Development); common::test_hello(); } diff --git a/examples/config/tests/production.rs b/examples/config/tests/production.rs index 08397303..b939739a 100644 --- a/examples/config/tests/production.rs +++ b/examples/config/tests/production.rs @@ -2,12 +2,11 @@ #![plugin(rocket_codegen)] extern crate rocket; -use rocket::config::Environment; mod common; #[test] -fn test() { - common::test_config(Environment::Production); +fn test_production_config() { + common::test_config(rocket::config::Environment::Production); common::test_hello(); } diff --git a/examples/config/tests/staging.rs b/examples/config/tests/staging.rs index fcb1c519..2d5f8981 100644 --- a/examples/config/tests/staging.rs +++ b/examples/config/tests/staging.rs @@ -2,12 +2,11 @@ #![plugin(rocket_codegen)] extern crate rocket; -use rocket::config::Environment; mod common; #[test] -fn test() { - common::test_config(Environment::Staging); +fn test_staging_config() { + common::test_config(rocket::config::Environment::Staging); common::test_hello(); }