~ubuntu-branches/ubuntu/raring/libmonitoring-livestatus-class-perl/raring-proposed

« back to all changes in this revision

Viewing changes to t/10-filter.t

  • Committer: Package Import Robot
  • Author(s): Alexander Wirt
  • Date: 2012-09-23 12:52:44 UTC
  • Revision ID: package-import@ubuntu.com-20120923125244-tj2b60nma3530edj
Tags: upstream-0.3
ImportĀ upstreamĀ versionĀ 0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!perl
 
2
 
 
3
use Test::More;
 
4
 
 
5
use_ok('Monitoring::Livestatus::Class::Abstract::Filter');
 
6
 
 
7
my @testings = (
 
8
    [[]], [],
 
9
    [[{ name => undef }], { name => 'localhost' }, []], ["Filter: name =", "Filter: name = localhost"],
 
10
    { name => undef }, ["Filter: name ="],
 
11
    { name => 'localhost' }, ["Filter: name = localhost"],
 
12
    { name => 'localhost', service => 'ping' }, [ "Filter: name = localhost", "Filter: service = ping" ],
 
13
    { name => [qw/localhost router/] }, [ "Filter: name = localhost", "Filter: name = router" ],
 
14
    [
 
15
        { name => 'localhost' },
 
16
        { name => 'router' },
 
17
    ], [ "Filter: name = localhost", "Filter: name = router" ],
 
18
    # not supported at the moment
 
19
    { name => { '-or' => [ qw/localhost router/] } },[ "Filter: name = localhost", "Filter: name = router", "Or: 2" ],
 
20
    { '-or' => [
 
21
            scheduled_downtime_depth => { '>' => '0' },
 
22
            host_scheduled_downtime_depth => { '>' => '0'},
 
23
        ]
 
24
    },['Filter: scheduled_downtime_depth > 0','Filter: host_scheduled_downtime_depth > 0','Or: 2'],
 
25
    {
 
26
        '-or' => {
 
27
            '-and' => { state => '2', acknowledged => '1', },
 
28
            state => '0',
 
29
        }
 
30
    },['Filter: acknowledged = 1', 'Filter: state = 2', 'And: 2', 'Filter: state = 0', 'Or: 2'],
 
31
    {
 
32
        '-or' => [
 
33
            { host_has_been_checked => 0, },
 
34
            {
 
35
                '-and' => {
 
36
                    host_state            => 1,
 
37
                    host_has_been_checked => 1,
 
38
                }
 
39
            },
 
40
            {
 
41
                '-and' => {
 
42
                    host_state            => 2,
 
43
                    host_has_been_checked => 1,
 
44
                }
 
45
            },
 
46
        ]
 
47
    },['Filter: host_has_been_checked = 0','Filter: host_state = 1','Filter: host_has_been_checked = 1','And: 2','Filter: host_state = 2','Filter: host_has_been_checked = 1','And: 2','Or: 3',],
 
48
    {
 
49
        '-or' => [
 
50
            { host_has_been_checked => 0, },
 
51
            {
 
52
                '-and' => {
 
53
                    host_state            => 1,
 
54
                    host_has_been_checked => 1,
 
55
                }
 
56
            },
 
57
            {
 
58
                '-and' => {
 
59
                    host_state            => 3,
 
60
                    host_has_been_checked => 1,
 
61
                }
 
62
            },
 
63
        ],
 
64
        '-and' => [
 
65
            scheduled_downtime_depth => { '>' => '0' },
 
66
            scheduled_downtime_depth => 0,
 
67
            acknowledged => [qw/0 1/],
 
68
            checks_enabled => [qw/0 1/],
 
69
            event_handler_enabled   => [qw/0 1/],
 
70
            flap_detection_enabled => [qw/0 1/],
 
71
            is_flapping => [qw/0 1/],
 
72
            notifications_enabled => [qw/0 1/],
 
73
            accept_passive_checks => [qw/0 1/],
 
74
        ]
 
75
    },[
 
76
        'Filter: host_has_been_checked = 0',
 
77
        'Filter: host_state = 1',
 
78
        'Filter: host_has_been_checked = 1',
 
79
        'And: 2',
 
80
        'Filter: host_state = 3',
 
81
        'Filter: host_has_been_checked = 1',
 
82
        'And: 2',
 
83
        'Or: 3',
 
84
        'Filter: scheduled_downtime_depth > 0',
 
85
        'Filter: scheduled_downtime_depth = 0',
 
86
        'Filter: acknowledged = 0',
 
87
        'Filter: acknowledged = 1',
 
88
        'Filter: checks_enabled = 0',
 
89
        'Filter: checks_enabled = 1',
 
90
        'Filter: event_handler_enabled = 0',
 
91
        'Filter: event_handler_enabled = 1',
 
92
        'Filter: flap_detection_enabled = 0',
 
93
        'Filter: flap_detection_enabled = 1',
 
94
        'Filter: is_flapping = 0',
 
95
        'Filter: is_flapping = 1',
 
96
        'Filter: notifications_enabled = 0',
 
97
        'Filter: notifications_enabled = 1',
 
98
        'Filter: accept_passive_checks = 0',
 
99
        'Filter: accept_passive_checks = 1',
 
100
        'And: 16'
 
101
        ],
 
102
    # Simple operator tests
 
103
    { name => { '=' => [ qw/localhost router/] } },[ "Filter: name = localhost", "Filter: name = router" ],
 
104
    { name => { '~' => [ qw/localhost router/] } },[ "Filter: name ~ localhost", "Filter: name ~ router" ],
 
105
    { name => { '~=' => [ qw/localhost router/] } },[ "Filter: name ~= localhost", "Filter: name ~= router" ],
 
106
    { name => { '~~' => [ qw/localhost router/] } },[ "Filter: name ~~ localhost", "Filter: name ~~ router" ],
 
107
    { name => { '<' => [ qw/localhost router/] } },[ "Filter: name < localhost", "Filter: name < router" ],
 
108
    { name => { '>' => [ qw/localhost router/] } },[ "Filter: name > localhost", "Filter: name > router" ],
 
109
    { name => { '<=' => [ qw/localhost router/] } },[ "Filter: name <= localhost", "Filter: name <= router" ],
 
110
    { name => { '>=' => [ qw/localhost router/] } },[ "Filter: name >= localhost", "Filter: name >= router" ],
 
111
    { host_scheduled_downtime_depth => { '>' => 0 } },[ "Filter: host_scheduled_downtime_depth > 0" ],
 
112
);
 
113
 
 
114
for ( my $i = 0 ; $i < scalar @testings ; $i++ ) {
 
115
    my $search            = $testings[$i];
 
116
    my $expected_statment = $testings[ ++$i ];
 
117
    my $filter_obj        = Monitoring::Livestatus::Class::Abstract::Filter->new();
 
118
    my $got_statment;
 
119
    eval {
 
120
        $got_statment = $filter_obj->apply($search);
 
121
    } or  warn @_;
 
122
    is_deeply( $got_statment, $expected_statment,
 
123
        sprintf( "Test %d - %s", ( $i / 2 ) + 1 , join " ",@{ $expected_statment } ));
 
124
}
 
125
 
 
126
done_testing;