Compare commits
No commits in common. "dddad6f0cca0cb9e709d7db813e775e8e605d37e" and "f4ce83b5c2b7c7929454e3c3713ac0db308ba42f" have entirely different histories.
dddad6f0cc
...
f4ce83b5c2
1 changed files with 20 additions and 21 deletions
|
@ -92,31 +92,31 @@ fn build_database_url() -> String {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use temp_env::{with_vars, with_vars_unset};
|
use temp_env::with_vars;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn build_database_url_with_defaults() {
|
fn build_database_url_with_defaults() {
|
||||||
temp_env::with_vars(
|
temp_env::with_vars([("DB_HOST", None::<&str>)], || {
|
||||||
[
|
// Was sieht die direkte Umgebung? (Sollte Err sein)
|
||||||
("DB_USER", None::<&str>),
|
println!(
|
||||||
("DB_NAME", None::<&str>),
|
"Inside temp_env (unset): std::env::var(\"DB_HOST\") is {:?}",
|
||||||
("DB_PASSWORD", None::<&str>),
|
std::env::var("DB_HOST")
|
||||||
("DB_HOST", Some("localhost")),
|
|
||||||
("DB_PORT", None::<&str>),
|
|
||||||
],
|
|
||||||
|| {
|
|
||||||
let expected_url = "postgresql://pgg:pgg@localhost:5432/pgg";
|
|
||||||
let actual_url = build_database_url();
|
|
||||||
assert_eq!(
|
|
||||||
actual_url, expected_url,
|
|
||||||
"Database URL should use default values for unset env vars."
|
|
||||||
);
|
);
|
||||||
},
|
|
||||||
|
// Was sieht dotenvy? (Ist wahrscheinlich Ok(...) wegen .env)
|
||||||
|
println!(
|
||||||
|
"Inside temp_env (unset): dotenvy::var(\"DB_HOST\") is {:?}",
|
||||||
|
dotenvy::var("DB_HOST")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Jetzt der Aufruf, der panicen sollte
|
||||||
|
build_database_url();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn build_database_url_with_all_vars() {
|
fn build_database_url_with_all_vars() {
|
||||||
|
dotenvy::dotenv().ok();
|
||||||
with_vars(
|
with_vars(
|
||||||
[
|
[
|
||||||
("DB_USER", Some("testuser")),
|
("DB_USER", Some("testuser")),
|
||||||
|
@ -139,8 +139,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic(expected = "DB_HOST must be set in .env")]
|
#[should_panic(expected = "DB_HOST must be set in .env")]
|
||||||
fn build_database_url_missing_host_panics() {
|
fn build_database_url_missing_host_panics() {
|
||||||
with_vars_unset(["DB_HOST"], || {
|
dotenvy::dotenv().ok();
|
||||||
build_database_url();
|
build_database_url();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue