Skip to content

Commit 14110eb

Browse files
Merge #940
940: Better error messages for empty string ENV variables r=carols10cents Fixes up #937, which was caused by me not having the `TEST_DATABASE_URL` set i.e. it was `TEST_DATABASE_URL=`. Thanks to Arnavion on the #rust channel for pointing out I could use unwrap_or() to cover both the `None` and `""` cases at once :).
2 parents 482d461 + 6a22f97 commit 14110eb

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/tests/all.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,17 @@ fn app() -> (record::Bomb, Arc<App>, conduit_middleware::MiddlewareBuilder) {
139139
return (bomb, app, middleware);
140140
}
141141

142+
// Return the environment variable only if it has been defined
142143
fn env(s: &str) -> String {
143-
match env::var(s).ok() {
144-
Some(s) => s,
145-
None => panic!("must have `{}` defined", s),
144+
// Handles both the `None` and empty string cases e.g. VAR=
145+
// by converting `None` to an empty string
146+
let env_result = env::var(s).ok().unwrap_or(String::new());
147+
148+
if env_result == "" {
149+
panic!("must have `{}` defined", s);
146150
}
151+
152+
env_result
147153
}
148154

149155
fn req(app: Arc<App>, method: conduit::Method, path: &str) -> MockRequest {

0 commit comments

Comments
 (0)