Skip to content

Commit 34c63bf

Browse files
committed
Handle window by cfg-gating the check for a host type
1 parent fa5fb61 commit 34c63bf

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

database/src/tests/mod.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ impl TestContext {
3030
.expect("Cannot create database");
3131
drop(client);
3232

33+
let host = match &config
34+
.get_hosts()
35+
.first()
36+
.expect("connection string must contain at least one host")
37+
{
38+
Host::Tcp(host) => host,
39+
40+
// This variant only exists on Unix targets, so the arm itself is
41+
// cfg-gated to keep non-unix builds happy.
42+
#[cfg(unix)]
43+
Host::Unix(_) => panic!("Unix sockets in Postgres connection string are not supported"),
44+
45+
// On non-unix targets the enum has no other variants.
46+
#[cfg(not(unix))]
47+
_ => unreachable!("non-TCP hosts cannot appear on this platform"),
48+
};
49+
3350
// We need to connect to the database against, because Postgres doesn't allow
3451
// changing the active database mid-connection.
3552
// There does not seem to be a way to turn the config back into a connection
@@ -38,11 +55,7 @@ impl TestContext {
3855
"postgresql://{}:{}@{}:{}/{}",
3956
config.get_user().unwrap(),
4057
String::from_utf8(config.get_password().unwrap().to_vec()).unwrap(),
41-
match &config.get_hosts()[0] {
42-
Host::Tcp(host) => host,
43-
Host::Unix(_) =>
44-
panic!("Unix sockets in Postgres connection string are not supported"),
45-
},
58+
host,
4659
&config.get_ports()[0],
4760
db_name
4861
);

0 commit comments

Comments
 (0)