Code

Removing CVS/SVN tags and replacing with git-based versioning
[nagiosplug.git] / plugins-scripts / t / utils.t
1 #!/usr/bin/perl -w -I ..
2 #
3 # utils.pm tests
4 #
5 #
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,
39         };
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});
45 }
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");