Net-OpenSSH-More-Linux.t 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. use strict;
  2. use warnings;
  3. use Test2::V0;
  4. use Test2::Tools::Explain;
  5. use Test2::Tools::Subtest qw{subtest_streamed};
  6. use Test2::Plugin::NoWarnings;
  7. use Test::MockModule qw{strict};
  8. use FindBin;
  9. use lib "$FindBin::Bin/../lib";
  10. use Net::OpenSSH::More::Linux;
  11. subtest_streamed "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::Linux->new(
  15. 'host' => 'localhost', 'use_persistent_shell' => 0, 'retry_max' => 1,
  16. );
  17. is( ref $obj, 'Net::OpenSSH::More::Linux', "Got right ref type for object upon instantiation (using localhost)" );
  18. my $adapter = $obj->get_primary_adapter(1);
  19. ok( $adapter, "Got something back as the primary adapter (use_local)" );
  20. is( $obj->get_primary_adapter(), $adapter, "Got expected adapter (remote)" );
  21. };
  22. # Mock based testing
  23. subtest_streamed "Common tests using mocks" => sub {
  24. local %Net::OpenSSH::More::cache;
  25. my $parent_mock = Test::MockModule->new('Net::OpenSSH::More');
  26. $parent_mock->redefine(
  27. 'new' => sub { bless {}, $_[0] },
  28. 'check_master' => 1,
  29. 'DESTROY' => undef,
  30. );
  31. my $obj = Net::OpenSSH::More::Linux->new( 'host' => 'localhost', retry_max => 1 );
  32. is( ref $obj, 'Net::OpenSSH::More::Linux', "Got right ref type for object upon instantiation" );
  33. };
  34. done_testing();