Skip to content

Commit 6a22f97

Browse files
Empty string error case for .env variables now covered
1 parent 172729a commit 6a22f97

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
@@ -138,11 +138,17 @@ fn app() -> (record::Bomb, Arc<App>, conduit_middleware::MiddlewareBuilder) {
138138
return (bomb, app, middleware);
139139
}
140140

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

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

0 commit comments

Comments
 (0)