utils.t 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/perl -w -I ..
  2. #
  3. # utils.pm tests
  4. #
  5. # $Id$
  6. #
  7. # Run with perl t/utils.t
  8. use warnings;
  9. use strict;
  10. use Test::More;
  11. use NPTest;
  12. use lib "..";
  13. use utils;
  14. my $hostname_checks = {
  15. "www.altinity.com" => 1,
  16. "www.888.com" => 1,
  17. "888.com" => 1,
  18. "host-hyphened.com" => 1,
  19. "rubbish" => 1,
  20. "-start.com" => 0,
  21. "nonfqdn-but-endsindot." => 1,
  22. "fqdn.and.endsindot." => 1,
  23. "lots.of.dots.dot.org" => 1,
  24. "endingwithdoubledots.." => 0,
  25. "toomany..dots" => 0,
  26. ".start.with.dot" => 0,
  27. "10.20.30.40" => 1,
  28. "10.20.30.40.50" => 0,
  29. "10.20.30" => 0,
  30. "10.20.30.40." => 1, # This is considered a hostname because of trailing dot. It probably won't exist though...
  31. "888." => 1, # This is because it could be a domain
  32. "host.888." => 1,
  33. "where.did.that.!.come.from." => 0,
  34. "no.underscores_.com" => 0,
  35. "a.somecompany.com" => 1,
  36. "host.a.com" => 1,
  37. };
  38. plan tests => ((scalar keys %$hostname_checks) + 4);
  39. foreach my $h (sort keys %$hostname_checks) {
  40. is (utils::is_hostname($h), $hostname_checks->{$h}, "$h should return ".$hostname_checks->{$h});
  41. }
  42. is(utils::is_hostname(), 0, "No parameter errors");
  43. is(utils::is_hostname(""), 0, "Empty string errors");
  44. is(utils::is_hostname(0), 0, "0 also errors");
  45. is(utils::is_hostname(1), 0, "1 also errors");