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