File: 54dump.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 (93 lines) | stat: -r--r--r-- 2,853 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/perl

use strict;
use Test::More qw(no_plan);
use Test::NoWarnings;
use File::Temp qw(tempfile);
use Data::Dumper;
use Scalar::Util qw(blessed);
use lib qw( ./lib ../lib );
eval { chdir('t') };
$Data::Dumper::Deparse = 1;

use_ok('Nagios::Object');

my %test_host = (
    host_name                    => 'localhost',
    alias                        => 'localhost',
    address                      => '127.0.0.1',
    check_command                => 'check-host-alive',
    max_check_attempts           => 3,
    checks_enabled               => 1,
    event_handler                => 'command_name',
    event_handler_enabled        => 0,
    low_flap_threshold           => 0,
    high_flap_threshold          => 0,
    flap_detection_enabled       => 0,
    process_perf_data            => 1,
    retain_status_information    => 1,
    retain_nonstatus_information => 1,
    notification_interval        => 120,
    notification_options         => [qw(d u r)],
    notifications_enabled        => 1,
    stalking_options             => [qw(o d u)]
);

diag("create a test Nagios::Host object") if ( $ENV{TEST_VERBOSE} );
my $host = Nagios::Host->new(%test_host);

ok( my $dump1 = $host->dump, "call dump()" );
is( $dump1, $host->dump, "output is consistent across calls to dump()" );

is( $host->name, $test_host{host_name}, "name() method works as expected" );

use_ok("Nagios::Object::Config");

# write the dumped config out to a file
my ( $fh, $filename ) = tempfile();
print $fh $dump1;
close $fh;

#warn $dump1;

my $config = Nagios::Object::Config->new();
$config->parse($filename);

#warn Dumper($config);
ok( my $file_host = $config->find_object( $test_host{host_name} ),
    "Retrieve the object from the parsed configuration."
);

isnt( "$host", "$file_host", "parsed object is not a copy" );

foreach my $key ( sort keys %test_host ) {
    is_deeply( $host->$key, $file_host->$key, "$key matches" );
}

# test for rt#17945
my $some_command = "foo";
my $timeperiod   = 5;

my $generic_host = Nagios::Host->new(
    register                     => 0,
    parents                      => undef,
    check_command                => $some_command,
    max_check_attempts           => 3,
    checks_enabled               => 1,
    event_handler                => $some_command,
    event_handler_enabled        => 0,
    low_flap_threshold           => 0,
    high_flap_threshold          => 0,
    flap_detection_enabled       => 0,
    process_perf_data            => 1,
    retain_status_information    => 1,
    retain_nonstatus_information => 1,
    notification_interval        => $timeperiod,
    notification_options         => [qw(d u r)],
    notifications_enabled        => 1,
    stalking_options             => [qw(o d u)]
);
isa_ok( $generic_host, 'Nagios::Host' );

ok( $generic_host->dump(), "rt#17945 - dump ok" );