Code

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