4
0

utils.t 1.2 KB

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