File: find_object-template.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 (36 lines) | stat: -r--r--r-- 915 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl

use strict;
use warnings;
use Test::More;
use lib qw( ../lib ./lib );

BEGIN { plan tests => 3 }

use Nagios::Object::Config;

my $err = 0;
my $file = 'find_object-template.cfg';

my @types = qw/Nagios::ServiceEscalation Nagios::HostEscalation Nagios::ServiceDependency/;
my @methods = qw/list_serviceescalations list_hostescalations list_servicedependencies/;

eval { chdir('t'); };

my $obj = Nagios::Object::Config->new();
$obj->parse($file) || die "Could not parse object file ($file)\n";
$obj->resolve_objects();

for (my $i = 0; $i < scalar @types; $i++) {
	my $method = $methods[$i];
	foreach my $o ( @{$obj->$method()} ) {
		# If we have use a template, find that object.
		if ( exists $o->{'use'} && defined $o->{'use'} ) {
			my $res = $obj->find_object($o->{'use'}, $types[$i]);
			my $ref = ref $res;
			ok( $ref eq $types[$i], "Looking for a $types[$i] object" );
		}
	}
}

exit $err;