Compare commits
No commits in common. "9346f3a39b991bce6cc82746ce5d24b98f2f042e" and "7a7c44c0bfb110bcf98198e6979d41fbdac010e1" have entirely different histories.
9346f3a39b
...
7a7c44c0bf
1 changed files with 3 additions and 56 deletions
|
@ -157,61 +157,8 @@ 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() {
|
||||||
// Clear the environment variable completely
|
with_vars_unset(["DB_HOST"], || {
|
||||||
unsafe { std::env::remove_var("DB_HOST") };
|
build_database_url();
|
||||||
build_database_url();
|
});
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn connect_to_redis_database_with_defaults() {
|
|
||||||
// This test requires a running Redis instance
|
|
||||||
// We're mocking the successful connection here
|
|
||||||
with_vars(
|
|
||||||
[
|
|
||||||
("REDIS_HOST", Some("localhost")),
|
|
||||||
("REDIS_PORT", None::<&str>),
|
|
||||||
],
|
|
||||||
|| {
|
|
||||||
let expected_conn_string = "redis://localhost:6379";
|
|
||||||
|
|
||||||
// Just verify the connection string format is correct
|
|
||||||
// Actual connection would need integration tests
|
|
||||||
let redis_host = dotenvy::var("REDIS_HOST").unwrap_or_default();
|
|
||||||
let redis_port = dotenvy::var("REDIS_PORT")
|
|
||||||
.map(|x| x.parse::<u16>().unwrap_or(6379))
|
|
||||||
.unwrap_or(6379);
|
|
||||||
let actual_conn_string = format!("redis://{}:{}", redis_host, redis_port);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
actual_conn_string, expected_conn_string,
|
|
||||||
"Redis connection string should use default port when not specified."
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn connect_to_redis_database_with_custom_port() {
|
|
||||||
with_vars(
|
|
||||||
[
|
|
||||||
("REDIS_HOST", Some("redis.internal")),
|
|
||||||
("REDIS_PORT", Some("6380")),
|
|
||||||
],
|
|
||||||
|| {
|
|
||||||
let expected_conn_string = "redis://redis.internal:6380";
|
|
||||||
|
|
||||||
// Verify connection string format
|
|
||||||
let redis_host = dotenvy::var("REDIS_HOST").unwrap_or_default();
|
|
||||||
let redis_port = dotenvy::var("REDIS_PORT")
|
|
||||||
.map(|x| x.parse::<u16>().unwrap_or(6379))
|
|
||||||
.unwrap_or(6379);
|
|
||||||
let actual_conn_string = format!("redis://{}:{}", redis_host, redis_port);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
actual_conn_string, expected_conn_string,
|
|
||||||
"Redis connection string should use specified host and port."
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue