diff options
author | Alex Bradley <a.bradley@alumni.cs.ubc.ca> | 2012-10-03 22:54:24 (GMT) |
---|---|---|
committer | Alex Bradley <a.bradley@alumni.cs.ubc.ca> | 2012-10-03 22:54:24 (GMT) |
commit | 13e85a0f4f9d1ede624e1135f1646c64ecc052a4 (patch) | |
tree | 7f530ec0003cfe599da8ffa6e17472175d67ce84 /plugins/t/check_apt.t | |
parent | 09c25be0d1c95ce1deba7d9ee046b343cbd7ab93 (diff) | |
download | monitoring-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.t | 90 |
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 | |||
7 | use strict; | ||
8 | use Test::More; | ||
9 | use NPTest; | ||
10 | |||
11 | sub 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 | |||
25 | if (-x "./check_apt") { | ||
26 | plan tests => 28; | ||
27 | } else { | ||
28 | plan skip_all => "No check_apt compiled"; | ||
29 | } | ||
30 | |||
31 | my $result; | ||
32 | |||
33 | my $testfile_command = "./check_apt %s --input-file=t/check_apt_input/%s"; | ||
34 | |||
35 | $result = NPTest->testCmd( sprintf($testfile_command, "", "debian1") ); | ||
36 | is( $result->return_code, 0, "No upgrades" ); | ||
37 | like( $result->output, make_result_regexp(0, 0), "Output correct" ); | ||
38 | |||
39 | $result = NPTest->testCmd( sprintf($testfile_command, "", "debian2") ); | ||
40 | is( $result->return_code, 1, "Debian apt output, warning" ); | ||
41 | like( $result->output, make_result_regexp(13, 0), "Output correct" ); | ||
42 | |||
43 | $result = NPTest->testCmd( sprintf($testfile_command, "", "debian3") ); | ||
44 | is( $result->return_code, 2, "Debian apt output, some critical" ); | ||
45 | like( $result->output, make_result_regexp(19, 4), "Output correct" ); | ||
46 | |||
47 | $result = NPTest->testCmd( sprintf($testfile_command, "-c '^[^\\(]*\\(.* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)'", "debian3") ); | ||
48 | is( $result->return_code, 2, "Debian apt output - should have same result when default security regexp specified via -c" ); | ||
49 | like( $result->output, make_result_regexp(19, 4), "Output correct" ); | ||
50 | |||
51 | $result = NPTest->testCmd( sprintf($testfile_command, "-i libc6", "debian3") ); | ||
52 | is( $result->return_code, 1, "Debian apt output, filter for libc6" ); | ||
53 | like( $result->output, make_result_regexp(3, 0), "Output correct" ); | ||
54 | |||
55 | $result = NPTest->testCmd( sprintf($testfile_command, "-i libc6 -i xen", "debian3") ); | ||
56 | is( $result->return_code, 2, "Debian apt output, filter for libc6 and xen" ); | ||
57 | like( $result->output, make_result_regexp(9, 4), "Output correct" ); | ||
58 | |||
59 | $result = NPTest->testCmd( sprintf($testfile_command, "-i libc6 -i xen -i linux", "debian3") ); | ||
60 | is( $result->return_code, 2, "Debian apt output, filter for libc6, xen, linux" ); | ||
61 | like( $result->output, make_result_regexp(12, 4), "Output correct" ); | ||
62 | |||
63 | $result = NPTest->testCmd( sprintf($testfile_command, "-e libc6", "debian3") ); | ||
64 | is( $result->return_code, 2, "Debian apt output, filter out libc6" ); | ||
65 | like( $result->output, make_result_regexp(16, 4), "Output correct" ); | ||
66 | |||
67 | $result = NPTest->testCmd( sprintf($testfile_command, "-e libc6 -e xen", "debian3") ); | ||
68 | is( $result->return_code, 1, "Debian apt output, filter out libc6 and xen" ); | ||
69 | like( $result->output, make_result_regexp(10, 0), "Output correct" ); | ||
70 | |||
71 | $result = NPTest->testCmd( sprintf($testfile_command, "-e libc6 -e xen -e linux", "debian3") ); | ||
72 | is( $result->return_code, 1, "Debian apt output, filter out libc6, xen, linux" ); | ||
73 | like( $result->output, make_result_regexp(7, 0), "Output correct" ); | ||
74 | |||
75 | $result = NPTest->testCmd( sprintf($testfile_command, "-c Debian-Security -c linux", "debian3") ); | ||
76 | is( $result->return_code, 2, "Debian apt output, critical on Debian-Security or linux" ); | ||
77 | like( $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") ); | ||
80 | is( $result->return_code, 2, "Debian apt output, include lib and linux, exclude gc1c, critical on linux-image" ); | ||
81 | like( $result->output, make_result_regexp(10, 2), "Output correct" ); | ||
82 | |||
83 | $result = NPTest->testCmd( sprintf($testfile_command, "", "ubuntu1") ); | ||
84 | is( $result->return_code, 1, "Ubuntu apt output, warning" ); | ||
85 | like( $result->output, make_result_regexp(5, 0), "Output correct" ); | ||
86 | |||
87 | $result = NPTest->testCmd( sprintf($testfile_command, "", "ubuntu2") ); | ||
88 | is( $result->return_code, 2, "Ubuntu apt output, some critical" ); | ||
89 | like( $result->output, make_result_regexp(25, 14), "Output correct" ); | ||
90 | |||