@@ -50,12 +50,16 @@ impl CreateUserBuilder {
5050
5151 /// Create a new [`CreateUserBuilder`] from [Settings]
5252 pub fn from ( settings : & dyn Settings ) -> Self {
53- Self :: new ( )
53+ let mut builder = Self :: new ( )
5454 . program_dir ( settings. get_binary_dir ( ) )
5555 . host ( settings. get_host ( ) )
5656 . port ( settings. get_port ( ) )
5757 . username ( settings. get_username ( ) )
58- . pg_password ( settings. get_password ( ) )
58+ . pg_password ( settings. get_password ( ) ) ;
59+ if let Some ( socket_dir) = settings. get_socket_dir ( ) {
60+ builder = builder. host ( socket_dir. to_string_lossy ( ) . to_string ( ) ) ;
61+ }
62+ builder
5963 }
6064
6165 /// Location of the program binary
@@ -441,6 +445,7 @@ impl CommandBuilder for CreateUserBuilder {
441445mod tests {
442446 use super :: * ;
443447 use crate :: TestSettings ;
448+ use crate :: TestSocketSettings ;
444449 use crate :: traits:: CommandToString ;
445450 use test_log:: test;
446451
@@ -516,4 +521,20 @@ mod tests {
516521 command. to_command_string( )
517522 ) ;
518523 }
524+
525+ #[ test]
526+ fn test_builder_from_socket ( ) {
527+ let command = CreateUserBuilder :: from ( & TestSocketSettings ) . build ( ) ;
528+ #[ cfg( not( target_os = "windows" ) ) ]
529+ let command_prefix = r#"PGPASSWORD="password" "./createuser" "# ;
530+ #[ cfg( target_os = "windows" ) ]
531+ let command_prefix = r#"".\\createuser" "# ;
532+
533+ assert_eq ! (
534+ format!(
535+ r#"{command_prefix}"--host" "/tmp/pg_socket" "--port" "5432" "--username" "postgres""#
536+ ) ,
537+ command. to_command_string( )
538+ ) ;
539+ }
519540}
0 commit comments