소스 검색

Widdly waaaa

Andy Baugh 3 달 전
부모
커밋
9e6b881360
2개의 변경된 파일18개의 추가작업 그리고 7개의 파일을 삭제
  1. 8 2
      lib/Net/OpenSSH/More.pm
  2. 10 5
      t/Net-OpenSSH-More.t

+ 8 - 2
lib/Net/OpenSSH/More.pm

@@ -175,6 +175,10 @@ my $ping = sub {
     else {
 	    my $host_info = first { $get_dns_record_from_hostname->( $opts->{'host'}, $_ ) } qw{A AAAA};
 	    ( $r_type ) = keys( %$host_info );
+        if(!$host_info->{$r_type}) {
+            require Data::Dumper;
+            die "Can't determine IP type. " . Data::Dumper::Dumper($host_info);
+        }
         $ip = $host_info->{$r_type};
     }
 	my %family_map = ( 'A' => 'INET', 'AAAA' => 'INET6' );
@@ -256,7 +260,7 @@ my $init_ssh = sub {
     foreach my $attempt ( 1 .. $opts->{'retry_max'} ) {
 
 		local $@;
-        my $up = eval { $ping->($opts) };
+        my $up = $ping->($opts);
         if ( !$up ) {
             $die_no_trace->("$opts->{'host'} is down!") if $opts->{die_on_drop};
             diag( { '_opts' => $opts }, "Waiting for host to bring up sshd, attempt $attempt..." );
@@ -264,7 +268,8 @@ my $init_ssh = sub {
         }
 
 		# Now, per the POD of Net::OpenSSH, new will NEVER DIE, so just trust it.
-        $self = $class->SUPER::new( delete $opts->{'host'}, %$opts );
+        my @base_module_opts = qw{user port password passphrase key_path gateway proxy_command batch_mode ctl_dir ctl_path ssh_cmd scp_cmd rsync_cmd remote_shell timeout kill_ssh_on_timeout strict_mode async connect master_opts default_ssh_opts forward_agent forward_X11 default_stdin_fh default_stdout_fh default_stderr_fh default_stdin_file default_stdout_file default_stderr_file master_stdout_fh master_sdterr_fh master_stdout_discard master_stderr_discard expand_vars vars external_master default_encoding default_stream_encoding default_argument_encoding password_prompt login_handler master_setpgrp master_pty_force};
+        $self = $class->SUPER::new( delete $opts->{'host'}, map{ $_ => $opts->{$_} } grep { $opts->{$_} } @base_module_opts );
 		my $error = $self->error;
         next unless ref $self eq 'Net::OpenSSH::More' && !$error;
 
@@ -475,6 +480,7 @@ my $do_persistent_command = sub {
 sub new {
     my ( $class, $host, %opts ) = @_;
     $die_no_trace->( "No host given to $class.", 'PEBCAK' ) if !$host;
+    $host = '127.0.0.1' if $host eq 'localhost';
 
     # Set defaults, check if we can return early
     %opts = ( %defaults, %opts );

+ 10 - 5
t/Net-OpenSSH-More.t

@@ -5,6 +5,7 @@ use Test2::V0;
 use Test2::Tools::Explain;
 use Test2::Plugin::NoWarnings;
 use Test::MockModule qw{strict};
+use Carp::Always;
 
 use FindBin;
 
@@ -12,6 +13,14 @@ use lib "$FindBin::Bin/../lib";
 
 use Net::OpenSSH::More;
 
+subtest "Live tests versus localhost" => sub {
+    plan 'skip_all' => 'AUTHOR_TESTS not set in shell environment, skipping...' if !$ENV{'AUTHOR_TESTS'};
+    my $obj = Net::OpenSSH::More->new( '127.0.0.1' );
+    is( ref $obj, 'Net::OpenSSH::More', "Got right ref type for object upon instantiation (using IP)" );
+    $obj = Net::OpenSSH::More->new( 'localhost' );
+    is( ref $obj, 'Net::OpenSSH::More', "Got right ref type for object upon instantiation (using localhost)" );
+};
+
 # Mock based testing
 subtest "Common tests using mocks" => sub {
     my $parent_mock = Test::MockModule->new('Net::OpenSSH');
@@ -25,9 +34,5 @@ subtest "Common tests using mocks" => sub {
     is( ref $obj, 'Net::OpenSSH::More', "Got right ref type for object upon instantiation" );
 };
 
-subtest "Live tests versus localhost" => sub {
-    plan 'skip_all' => 'AUTHOR_TESTS not set in shell environment, skipping...' if !$ENV{'AUTHOR_TESTS'};
-    pass("Unimplemented for now");
-};
-
+$Net::OpenSSH::More::disable_destructor = 0;
 done_testing();