From 6a22f9723e3f726a59ba5759b25c58d057db6282 Mon Sep 17 00:00:00 2001 From: Vignesh Date: Mon, 7 Aug 2017 17:35:32 +1000 Subject: [PATCH] Empty string error case for .env variables now covered --- src/tests/all.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/tests/all.rs b/src/tests/all.rs index 688e1ce98fb..29bf261acdc 100644 --- a/src/tests/all.rs +++ b/src/tests/all.rs @@ -138,11 +138,17 @@ fn app() -> (record::Bomb, Arc, conduit_middleware::MiddlewareBuilder) { return (bomb, app, middleware); } +// Return the environment variable only if it has been defined fn env(s: &str) -> String { - match env::var(s).ok() { - Some(s) => s, - None => panic!("must have `{}` defined", s), + // Handles both the `None` and empty string cases e.g. VAR= + // by converting `None` to an empty string + let env_result = env::var(s).ok().unwrap_or(String::new()); + + if env_result == "" { + panic!("must have `{}` defined", s); } + + env_result } fn req(app: Arc, method: conduit::Method, path: &str) -> MockRequest {