test(server): isolate config tests from ambient env via temp-env
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,17 +1,27 @@
|
||||
use clap::Parser;
|
||||
use server::Config;
|
||||
|
||||
const CLEARED: [(&str, Option<&str>); 3] = [
|
||||
("DATABASE_URL", None),
|
||||
("BIND_ADDR", None),
|
||||
("APP_NAME", None),
|
||||
];
|
||||
|
||||
#[test]
|
||||
fn parses_from_args_with_defaults() {
|
||||
let cfg = Config::try_parse_from(["server", "--database-url", "postgres://localhost/test"])
|
||||
.expect("should parse");
|
||||
temp_env::with_vars(CLEARED, || {
|
||||
let cfg = Config::try_parse_from(["server", "--database-url", "postgres://localhost/test"])
|
||||
.expect("should parse");
|
||||
|
||||
assert_eq!(cfg.database_url, "postgres://localhost/test");
|
||||
assert_eq!(cfg.bind_addr, "0.0.0.0:8080");
|
||||
assert_eq!(cfg.app_name, "Collection Management System");
|
||||
assert_eq!(cfg.database_url, "postgres://localhost/test");
|
||||
assert_eq!(cfg.bind_addr, "0.0.0.0:8080");
|
||||
assert_eq!(cfg.app_name, "Collection Management System");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn database_url_is_required() {
|
||||
assert!(Config::try_parse_from(["server"]).is_err());
|
||||
temp_env::with_vars(CLEARED, || {
|
||||
assert!(Config::try_parse_from(["server"]).is_err());
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user