Ver código fonte

Getting closer, need to do remote shimming, etc.

Andy Baugh 3 anos atrás
pai
commit
889e2e70db
2 arquivos alterados com 54 adições e 7 exclusões
  1. 48 5
      bin/rprove
  2. 6 2
      lib/App/Prove/Remote/Connector.pm

+ 48 - 5
bin/rprove

@@ -4,21 +4,64 @@ package App::Prove::Remote::rprove;
 use strict;
 use warnings;
 
-use experimental 'signatures';
-
 use App::Prove::Remote::Connector ();
 use Getopt::Long                  ();
 
 exit run() unless caller();
 
 sub run {
-    my ( $host, $verbosity, @tests ) = ('', '');
+    my ( $host, $verbosity, @tests ) = ('127.0.0.1', 0);
+    Getopt::Long::Configure( 'bundling', 'auto_help', 'pass_through' );
     Getopt::Long::GetOptions(
-        'host|h'    => \$host,
-        'verbosity' => \$verbosity,
+        'host|h=s'      => \$host,
+        'verbosity|v=i' => \$verbosity,
     );
     my $conn = App::Prove::Remote::Connector->new($host, $verbosity);
     return 0;
 }
 
 1;
+
+__END__
+
+=head1 NAME
+
+rprove - Prove wrapper which executes your tests on the remote host
+
+=head1 SYNOPSIS
+
+rprove [options] [file ...]
+
+ Options:
+   -help            You are reading it!
+   -host            Host to connect to. Defaults to 127.0.0.1.
+   -verbosity       How verbose you want this (and the SSH connection) to be
+
+=head1 OPTIONS
+
+=over 8
+
+=item B<-help>
+
+Print a brief help message and exits.
+
+=item B<-host>
+
+Host to connect to. Defaults to 127.0.0.1
+
+=item B<-verbosity>
+
+How verbose you want this to be. Useful if you need to debug
+some strange SSH behavior.
+
+=back
+
+=head1 DESCRIPTION
+
+B<rprove> will locally run prove with a --exec argument which is a shim.
+This (remote_shim.pl) will connect to the remote host for the test in
+question, upload it to a temporary directory and run it on the host.
+Output of the script is then read by the TAP parser as is expected for
+a seamless testing experience *as if you had ran the test locally*.
+
+=cut

+ 6 - 2
lib/App/Prove/Remote/Connector.pm

@@ -1,3 +1,5 @@
+package App::Prove::Remote::Connector;
+
 use strict;
 use warnings;
 
@@ -8,7 +10,7 @@ use experimental 'signatures';
 
 # Cache the connections/objects internally
 my ( $ssh, $sftp );
-sub new ( $class,  $host='127.0.0.1', $verbosity ) {
+sub new ( $class,  $host='127.0.0.1', $verbosity=0 ) {
     my $obj = bless {
         'ppid'      => $$, # May not need this ultimately
         'host'      => $host,
@@ -22,13 +24,15 @@ sub ssh ($self) {
     return $ssh if $ssh;
     print "# Connecting to $self->{'host'} via Net::OpenSSH" if $self->{'verbosity'} >= 1;
     $ssh = Net::OpenSSH->new($self->{'host'});
+    die "Couldn't establish SSH connection: ". $ssh->error if $ssh->error;
     return $ssh;
 }
 
 sub sftp ($self) {
     return $sftp if $sftp;
     print "# Connecting to $self->{'host'} via Net::SFTP::Foreign" if $self->{'verbosity'} >= 1;
-    $sftp = Net::SFTP::Foreign->new($self->{'host'});
+    $sftp = $self->ssh->sftp();
+    die "SFTP Connection failed: " . $sftp->error if $sftp->error;
     return $sftp;
 }