Net-OpenSSH-More.t 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. use strict;
  2. use warnings;
  3. use Test2::V0;
  4. use Test2::Tools::Explain;
  5. use Test2::Plugin::NoWarnings;
  6. use Test::MockModule qw{strict};
  7. use Carp::Always;
  8. use FindBin;
  9. use lib "$FindBin::Bin/../lib";
  10. use Net::OpenSSH::More;
  11. subtest "Live tests versus localhost" => sub {
  12. plan 'skip_all' => 'AUTHOR_TESTS not set in shell environment, skipping...' if !$ENV{'AUTHOR_TESTS'};
  13. local %Net::OpenSSH::More::cache;
  14. my $obj = Net::OpenSSH::More->new( '127.0.0.1' );
  15. is( ref $obj, 'Net::OpenSSH::More', "Got right ref type for object upon instantiation (using IP)" );
  16. $obj = Net::OpenSSH::More->new( 'localhost' );
  17. is( ref $obj, 'Net::OpenSSH::More', "Got right ref type for object upon instantiation (using localhost)" );
  18. };
  19. # Mock based testing
  20. subtest "Common tests using mocks" => sub {
  21. local %Net::OpenSSH::More::cache;
  22. my $parent_mock = Test::MockModule->new('Net::OpenSSH');
  23. $parent_mock->redefine(
  24. 'new' => sub { bless {}, $_[0] },
  25. 'check_master' => 1,
  26. );
  27. {
  28. # MockModule can't actually redefine destructors properly due to the mock also going out of scope.
  29. no warnings qw{redefine};
  30. *Net::OpenSSH::DESTROY = sub { undef };
  31. }
  32. local $Net::OpenSSH::More::disable_destructor = 1;
  33. my $obj = Net::OpenSSH::More->new( '127.0.0.1', retry_max => 1, 'output_prefix' => '# ' );
  34. is( ref $obj, 'Net::OpenSSH::More', "Got right ref type for object upon instantiation" );
  35. is( $obj->diag("Whee"), undef, "You should see whee before this subtest" );
  36. };
  37. done_testing();