File: nestedtemplates.t

package info (click to toggle)
libnagios-object-perl 0.21.20-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,032 kB
  • sloc: perl: 3,198; makefile: 9
file content (55 lines) | stat: -r--r--r-- 1,515 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl -w

use strict;
use Test::More qw(no_plan);
use Test::NoWarnings;
use Scalar::Util qw(blessed);
use lib qw( ../lib ./lib );
use Data::Dumper;

#$Data::Dumper::Maxdepth = 2;
#$Data::Dumper::Deparse = 1;

eval { chdir('t') };

use Nagios::Config;

my $config = Nagios::Object::Config->new();
$config->parse('nestedtemplates.cfg');

# this test verifies that the correct template name is being returned
foreach my $template ( $config->list_hosts ) {

    # get the names of the template and its parent for diagnostic output
    my $tname = $template->name;
    my $pname = $template->use || 'undefined';
    $pname = $pname->name if ( blessed $tname );
    my $message = "$pname isn't $tname (template name/object name)";

    # test!
    isnt( $template->use, $template->name, $message );
}

# now verify that object values are being returned properly with and
# without inheritance
# Note: these tests rely on the exact data in nestedtemplates.cfg

my $generic  = $config->find_object( 'generic-service', 'Nagios::Service' );
my $perfdata = $config->find_object( 'perfdata-only',   'Nagios::Service' );

isnt( $generic->name, $perfdata->name, "check template names" );
isnt(
    $generic->flap_detection_enabled,
    $perfdata->flap_detection_enabled,
    "check a value that should not be inherited"
);
is( $perfdata->retry_check_interval,
    $generic->retry_check_interval,
    "check a value that should be inherited"
);

#warn Dumper( $perfdata );

#warn $generic->dump;
#warn $perfdata->dump;