check_ntp.t 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #! /usr/bin/perl -w -I ..
  2. #
  3. # Testing NTP
  4. #
  5. # $Id$
  6. #
  7. use strict;
  8. use Test::More;
  9. use NPTest;
  10. plan tests => 4;
  11. my $res;
  12. my $ntp_service = getTestParameter( "NP_GOOD_NTP_SERVICE",
  13. "A host providing NTP service",
  14. "pool.ntp.org");
  15. my $no_ntp_service = getTestParameter( "NP_NO_NTP_SERVICE",
  16. "A host NOT providing the NTP service",
  17. "localhost" );
  18. my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
  19. "The hostname of system not responsive to network requests",
  20. "10.0.0.1" );
  21. my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
  22. "An invalid (not known to DNS) hostname",
  23. "nosuchhost");
  24. SKIP: {
  25. skip "No NTP server defined", 1 unless $ntp_service;
  26. $res = NPTest->testCmd(
  27. "./check_ntp -H $ntp_service"
  28. );
  29. cmp_ok( $res->return_code, '==', 0, "Got good NTP result");
  30. }
  31. SKIP: {
  32. skip "No bad NTP server defined", 1 unless $no_ntp_service;
  33. $res = NPTest->testCmd(
  34. "./check_ntp -H $no_ntp_service"
  35. );
  36. cmp_ok( $res->return_code, '==', 2, "Got bad NTP result");
  37. }
  38. $res = NPTest->testCmd(
  39. "./check_ntp -H $host_nonresponsive"
  40. );
  41. cmp_ok( $res->return_code, '==', 2, "Got critical if server not responding");
  42. $res = NPTest->testCmd(
  43. "./check_ntp -H $hostname_invalid"
  44. );
  45. cmp_ok( $res->return_code, '==', 3, "Got critical if server hostname invalid");