@@ -30,6 +30,23 @@ impl TestContext {
30
30
. expect ( "Cannot create database" ) ;
31
31
drop ( client) ;
32
32
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
+
33
50
// We need to connect to the database against, because Postgres doesn't allow
34
51
// changing the active database mid-connection.
35
52
// There does not seem to be a way to turn the config back into a connection
@@ -38,11 +55,7 @@ impl TestContext {
38
55
"postgresql://{}:{}@{}:{}/{}" ,
39
56
config. get_user( ) . unwrap( ) ,
40
57
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,
46
59
& config. get_ports( ) [ 0 ] ,
47
60
db_name
48
61
) ;
0 commit comments