Skip to content

Commit

Permalink
Add test for Config::url
Browse files Browse the repository at this point in the history
This is related to #290
  • Loading branch information
bikeshedder committed Dec 18, 2023
1 parent 62c8833 commit 7869a0b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions postgres/tests/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,36 @@ fn config_from_env() {
assert_eq!(pool_cfg.timeouts.create, Some(Duration::from_secs(2)));
assert_eq!(pool_cfg.timeouts.recycle, Some(Duration::from_secs(3)));
}

#[test]
fn config_url() {
let mut cfg = deadpool_postgres::Config {
url: Some("postgresql://zombie@localhost/deadpool".into()),
..Default::default()
};
{
let pg_cfg = cfg.get_pg_config().unwrap();
assert_eq!(pg_cfg.get_dbname(), Some("deadpool"));
assert_eq!(pg_cfg.get_user(), Some("zombie"));
assert_eq!(
pg_cfg.get_hosts(),
&[tokio_postgres::config::Host::Tcp("localhost".into())]
);
}
// now apply some overrides
{
cfg.dbname = Some("livepool".into());
cfg.host = Some("remotehost".into());
cfg.user = Some("human".into());
let pg_cfg = cfg.get_pg_config().unwrap();
assert_eq!(pg_cfg.get_dbname(), Some("livepool"));
assert_eq!(pg_cfg.get_user(), Some("human"));
assert_eq!(
pg_cfg.get_hosts(),
&[
tokio_postgres::config::Host::Tcp("localhost".into()),
tokio_postgres::config::Host::Tcp("remotehost".into()),
]
);
}
}

0 comments on commit 7869a0b

Please sign in to comment.