check_ssh.t 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #! /usr/bin/perl -w -I ..
  2. #
  3. # check_ssh tests
  4. #
  5. #
  6. use strict;
  7. use Test::More;
  8. use NPTest;
  9. # Required parameters
  10. my $ssh_host = getTestParameter("NP_SSH_HOST",
  11. "A host providing SSH service",
  12. "localhost");
  13. my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE",
  14. "The hostname of system not responsive to network requests",
  15. "10.0.0.1" );
  16. my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID",
  17. "An invalid (not known to DNS) hostname",
  18. "nosuchhost" );
  19. plan skip_all => "SSH_HOST must be defined" unless $ssh_host;
  20. plan tests => 6;
  21. my $result = NPTest->testCmd(
  22. "./check_ssh -H $ssh_host"
  23. );
  24. cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)");
  25. like($result->output, '/^SSH OK - /', "Status text if command returned none (OK)");
  26. $result = NPTest->testCmd(
  27. "./check_ssh -H $host_nonresponsive -t 2"
  28. );
  29. cmp_ok($result->return_code, '==', 2, "Exit with return code 0 (OK)");
  30. like($result->output, '/^CRITICAL - Socket timeout after 2 seconds/', "Status text if command returned none (OK)");
  31. $result = NPTest->testCmd(
  32. "./check_ssh -H $hostname_invalid -t 2"
  33. );
  34. cmp_ok($result->return_code, '==', 3, "Exit with return code 0 (OK)");
  35. like($result->output, '/^check_ssh: Invalid hostname/', "Status text if command returned none (OK)");