summaryrefslogtreecommitdiffstats
path: root/plugins/t/check_apt.t
diff options
context:
space:
mode:
authorAlex Bradley <a.bradley@alumni.cs.ubc.ca>2012-10-03 22:54:24 (GMT)
committerAlex Bradley <a.bradley@alumni.cs.ubc.ca>2012-10-03 22:54:24 (GMT)
commit13e85a0f4f9d1ede624e1135f1646c64ecc052a4 (patch)
tree7f530ec0003cfe599da8ffa6e17472175d67ce84 /plugins/t/check_apt.t
parent09c25be0d1c95ce1deba7d9ee046b343cbd7ab93 (diff)
downloadmonitoring-plugins-13e85a0f4f9d1ede624e1135f1646c64ecc052a4.tar.gz
Tests for check_aptrefs/pull/20/head
Add a hidden "--input-file" option to check_apt (modelled on check_procs) so that it can take files with sample apt output as input. Add tests for my SECURITY_RE fix (debian3) and for the include, exclude and critical options.
Diffstat (limited to 'plugins/t/check_apt.t')
-rw-r--r--plugins/t/check_apt.t90
1 files changed, 90 insertions, 0 deletions
diff --git a/plugins/t/check_apt.t b/plugins/t/check_apt.t
new file mode 100644
index 0000000..7123097
--- /dev/null
+++ b/plugins/t/check_apt.t
@@ -0,0 +1,90 @@
1#!/usr/bin/perl -w -I ..
2#
3# Test check_apt using input files.
4# Contributed by Alex Bradley, October 2012
5#
6
7use strict;
8use Test::More;
9use NPTest;
10
11sub make_result_regexp {
12 my ($warning, $critical) = @_;
13 my $status;
14 if ($warning == 0 && $critical == 0) {
15 $status = "OK";
16 } elsif ($critical == 0) {
17 $status = "WARNING";
18 } else {
19 $status = "CRITICAL";
20 }
21 return sprintf('/^APT %s: %d packages available for upgrade \(%d critical updates\).\s*$/',
22 $status, $warning, $critical);
23}
24
25if (-x "./check_apt") {
26 plan tests => 28;
27} else {
28 plan skip_all => "No check_apt compiled";
29}
30
31my $result;
32
33my $testfile_command = "./check_apt %s --input-file=t/check_apt_input/%s";
34
35$result = NPTest->testCmd( sprintf($testfile_command, "", "debian1") );
36is( $result->return_code, 0, "No upgrades" );
37like( $result->output, make_result_regexp(0, 0), "Output correct" );
38
39$result = NPTest->testCmd( sprintf($testfile_command, "", "debian2") );
40is( $result->return_code, 1, "Debian apt output, warning" );
41like( $result->output, make_result_regexp(13, 0), "Output correct" );
42
43$result = NPTest->testCmd( sprintf($testfile_command, "", "debian3") );
44is( $result->return_code, 2, "Debian apt output, some critical" );
45like( $result->output, make_result_regexp(19, 4), "Output correct" );
46
47$result = NPTest->testCmd( sprintf($testfile_command, "-c '^[^\\(]*\\(.* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)'", "debian3") );
48is( $result->return_code, 2, "Debian apt output - should have same result when default security regexp specified via -c" );
49like( $result->output, make_result_regexp(19, 4), "Output correct" );
50
51$result = NPTest->testCmd( sprintf($testfile_command, "-i libc6", "debian3") );
52is( $result->return_code, 1, "Debian apt output, filter for libc6" );
53like( $result->output, make_result_regexp(3, 0), "Output correct" );
54
55$result = NPTest->testCmd( sprintf($testfile_command, "-i libc6 -i xen", "debian3") );
56is( $result->return_code, 2, "Debian apt output, filter for libc6 and xen" );
57like( $result->output, make_result_regexp(9, 4), "Output correct" );
58
59$result = NPTest->testCmd( sprintf($testfile_command, "-i libc6 -i xen -i linux", "debian3") );
60is( $result->return_code, 2, "Debian apt output, filter for libc6, xen, linux" );
61like( $result->output, make_result_regexp(12, 4), "Output correct" );
62
63$result = NPTest->testCmd( sprintf($testfile_command, "-e libc6", "debian3") );
64is( $result->return_code, 2, "Debian apt output, filter out libc6" );
65like( $result->output, make_result_regexp(16, 4), "Output correct" );
66
67$result = NPTest->testCmd( sprintf($testfile_command, "-e libc6 -e xen", "debian3") );
68is( $result->return_code, 1, "Debian apt output, filter out libc6 and xen" );
69like( $result->output, make_result_regexp(10, 0), "Output correct" );
70
71$result = NPTest->testCmd( sprintf($testfile_command, "-e libc6 -e xen -e linux", "debian3") );
72is( $result->return_code, 1, "Debian apt output, filter out libc6, xen, linux" );
73like( $result->output, make_result_regexp(7, 0), "Output correct" );
74
75$result = NPTest->testCmd( sprintf($testfile_command, "-c Debian-Security -c linux", "debian3") );
76is( $result->return_code, 2, "Debian apt output, critical on Debian-Security or linux" );
77like( $result->output, make_result_regexp(19, 9), "Output correct" );
78
79$result = NPTest->testCmd( sprintf($testfile_command, "-i lib -i linux -e gc1c -c linux-image", "debian3") );
80is( $result->return_code, 2, "Debian apt output, include lib and linux, exclude gc1c, critical on linux-image" );
81like( $result->output, make_result_regexp(10, 2), "Output correct" );
82
83$result = NPTest->testCmd( sprintf($testfile_command, "", "ubuntu1") );
84is( $result->return_code, 1, "Ubuntu apt output, warning" );
85like( $result->output, make_result_regexp(5, 0), "Output correct" );
86
87$result = NPTest->testCmd( sprintf($testfile_command, "", "ubuntu2") );
88is( $result->return_code, 2, "Ubuntu apt output, some critical" );
89like( $result->output, make_result_regexp(25, 14), "Output correct" );
90