aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-10-05 09:11:46 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-10-05 09:11:46 +1300
commit8bbf87a18a276f69a5db849f9f5f8f3aef6a05b5 (patch)
treedc2cd3261157887c1599b2feb4ccd4bb47bc4a71
parentAdd another example (diff)
downloadList-Breakdown-8bbf87a18a276f69a5db849f9f5f8f3aef6a05b5.tar.gz
List-Breakdown-8bbf87a18a276f69a5db849f9f5f8f3aef6a05b5.zip
Fix new "monitoring" example, add test for it
-rw-r--r--lib/List/Breakdown.pm2
-rw-r--r--t/monitoring.t71
2 files changed, 72 insertions, 1 deletions
diff --git a/lib/List/Breakdown.pm b/lib/List/Breakdown.pm
index aab5afb..3cd3060 100644
--- a/lib/List/Breakdown.pm
+++ b/lib/List/Breakdown.pm
@@ -202,7 +202,7 @@ C<%results>:
hostname => 'webserver2',
status => 'CRITICAL'
}
- },
+ ],
unknown => []
}
)
diff --git a/t/monitoring.t b/t/monitoring.t
new file mode 100644
index 0000000..42bcb69
--- /dev/null
+++ b/t/monitoring.t
@@ -0,0 +1,71 @@
+#!perl -T
+
+use strict;
+use warnings;
+use utf8;
+
+use Test::More tests => 1;
+
+use List::Breakdown 'breakdown';
+
+our $VERSION = '0.11';
+
+my @checks = (
+ {
+ hostname => 'webserver1',
+ status => 'OK',
+ },
+ {
+ hostname => 'webserver2',
+ status => 'CRITICAL',
+ },
+ {
+ hostname => 'webserver3',
+ status => 'WARNING',
+ },
+ {
+ hostname => 'webserver4',
+ status => 'OK',
+ },
+);
+
+my %buckets = (
+ ok => sub { $_->{status} eq 'OK' },
+ problem => {
+ warning => sub { $_->{status} eq 'WARNING' },
+ critical => sub { $_->{status} eq 'CRITICAL' },
+ unknown => sub { $_->{status} eq 'UNKNOWN' },
+ },
+);
+
+my %results = breakdown \%buckets, @checks;
+
+my %expected = (
+ ok => [
+ {
+ hostname => 'webserver1',
+ status => 'OK',
+ },
+ {
+ hostname => 'webserver4',
+ status => 'OK',
+ },
+ ],
+ problem => {
+ warning => [
+ {
+ hostname => 'webserver3',
+ status => 'WARNING',
+ },
+ ],
+ critical => [
+ {
+ hostname => 'webserver2',
+ status => 'CRITICAL',
+ },
+ ],
+ unknown => [],
+ },
+);
+
+is_deeply( \%results, \%expected, 'monitoring' );