summaryrefslogtreecommitdiffstats
path: root/plugins/tests
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2006-01-30 16:10:50 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2006-01-30 16:10:50 +0000
commit795100ae5124915bb647a304d5dfe2ada2f44ab0 (patch)
treeb3fd0dc1a88ebb533f074c476ee020e32877632e /plugins/tests
parentc8a9bf228fdd34b021796f577a404cb8b0cba1f9 (diff)
downloadmonitoring-plugins-795100ae5124915bb647a304d5dfe2ada2f44ab0.tar.gz
Added libtap tests for utils.c library functions. Removed redundant
test files git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1303 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/tests')
-rw-r--r--plugins/tests/.cvsignore3
-rw-r--r--plugins/tests/Makefile.am21
-rw-r--r--plugins/tests/README5
-rw-r--r--plugins/tests/check_disk9
-rw-r--r--plugins/tests/check_dns9
-rw-r--r--plugins/tests/check_ftp9
-rw-r--r--plugins/tests/check_hpjd9
-rw-r--r--plugins/tests/check_http9
-rw-r--r--plugins/tests/check_load9
-rw-r--r--plugins/tests/check_ping13
-rw-r--r--plugins/tests/check_procs23
-rw-r--r--plugins/tests/check_swap13
-rw-r--r--plugins/tests/check_users9
-rw-r--r--plugins/tests/check_vsz9
-rw-r--r--plugins/tests/test_utils.c109
-rwxr-xr-xplugins/tests/test_utils.t6
16 files changed, 144 insertions, 121 deletions
diff --git a/plugins/tests/.cvsignore b/plugins/tests/.cvsignore
new file mode 100644
index 00000000..95112e15
--- /dev/null
+++ b/plugins/tests/.cvsignore
@@ -0,0 +1,3 @@
1Makefile
2Makefile.in
3test_utils
diff --git a/plugins/tests/Makefile.am b/plugins/tests/Makefile.am
new file mode 100644
index 00000000..0d82be12
--- /dev/null
+++ b/plugins/tests/Makefile.am
@@ -0,0 +1,21 @@
1
2noinst_PROGRAMS = @EXTRA_TEST@
3
4# These two lines support "make check", but we use "make test"
5TESTS = @EXTRA_TEST@
6check_PROGRAMS = @EXTRA_TEST@
7
8INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/intl
9
10EXTRA_PROGRAMS = test_utils
11
12LIBS = @LIBINTL@
13
14test_utils_SOURCES = test_utils.c
15test_utils_CFLAGS = -g -I..
16test_utils_LDFLAGS = -L..
17test_utils_LDADD = ../utils.o @EXTRA_TAPOBJ@
18
19test: ${noinst_PROGRAMS}
20 perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS)
21
diff --git a/plugins/tests/README b/plugins/tests/README
new file mode 100644
index 00000000..66935e4d
--- /dev/null
+++ b/plugins/tests/README
@@ -0,0 +1,5 @@
1The tests in here use the libtap library functions
2(http://jc.ngo.org.uk/trac-bin/trac.cgi/wiki/LibTap), so are
3more for unit testing the utils.c library functions.
4
5However, it probably should be merged into the plugins/t subdirectory.
diff --git a/plugins/tests/check_disk b/plugins/tests/check_disk
deleted file mode 100644
index c4323e0b..00000000
--- a/plugins/tests/check_disk
+++ /dev/null
@@ -1,9 +0,0 @@
1check_disk
2
3[normal]
4100 100 /
5^Disk ok - +[\.0-9]+
6
7[critical]
80 0 /
9^Only +[\.0-9]+
diff --git a/plugins/tests/check_dns b/plugins/tests/check_dns
deleted file mode 100644
index 2e9b9a09..00000000
--- a/plugins/tests/check_dns
+++ /dev/null
@@ -1,9 +0,0 @@
1check_dns
2
3[normal]
4127.0.0.1
5DNS ok - +[\.0-9]+ seconds response time, Address\(es\) is\/are 127\.0\.0\.1
6
7[critical]
8$nullhost
9DNS (problem - Probably a non-existent host/domain|CRITICAL - Non-existent host/domain|CRITICAL - Connection timed out after [0-9]+ seconds)
diff --git a/plugins/tests/check_ftp b/plugins/tests/check_ftp
deleted file mode 100644
index 4266ebdc..00000000
--- a/plugins/tests/check_ftp
+++ /dev/null
@@ -1,9 +0,0 @@
1check_ftp
2
3[normal]
4$hostname -wt 300 -ct 600
5FTP ok - [0-9]+ second response time
6
7[critical]
8$noserver -wt 0 -ct 0
9(Invalid FTP response received from host|Connection refused by host)
diff --git a/plugins/tests/check_hpjd b/plugins/tests/check_hpjd
deleted file mode 100644
index df35996f..00000000
--- a/plugins/tests/check_hpjd
+++ /dev/null
@@ -1,9 +0,0 @@
1check_hpjd
2
3[normal]
4$printer
5^Printer ok -
6
7[critical]
8$noserver
9Timeout: No response from ns
diff --git a/plugins/tests/check_http b/plugins/tests/check_http
deleted file mode 100644
index e09f6ff7..00000000
--- a/plugins/tests/check_http
+++ /dev/null
@@ -1,9 +0,0 @@
1check_http
2
3[normal]
4www.infoplease.com -wt 300 -ct 600
5HTTP/1.1 200 OK - [0-9]+ second response time
6
7[critical]
8$nullhost -wt 1 -ct 2
9(Connection refused by host|Network is unreachable|Connection refused or timed out|Socket timeout after [0-9]+ seconds)$
diff --git a/plugins/tests/check_load b/plugins/tests/check_load
deleted file mode 100644
index 5e4be3a4..00000000
--- a/plugins/tests/check_load
+++ /dev/null
@@ -1,9 +0,0 @@
1check_load
2
3[normal]
4100 100 100 100 100 100
5^load average: +[\.0-9]+, +[\.0-9]+, +[\.0-9]+$
6
7[critical]
80 0 0 0 0 0
9^load average: +[\.0-9]+, +[\.0-9]+, +[\.0-9]+ CRITICAL$
diff --git a/plugins/tests/check_ping b/plugins/tests/check_ping
deleted file mode 100644
index 115cbaa3..00000000
--- a/plugins/tests/check_ping
+++ /dev/null
@@ -1,13 +0,0 @@
1check_ping
2
3[normal]
4127.0.0.1 100 100 1000 1000 -p 1
5PING ok - Packet loss = +[0-9]{1,2}\%, +RTA = [\.0-9]+ ms
6
7[critical]
8127.0.0.1 0 0 0 0 -p 1
9Packet loss = +[0-9]{1,2}\%, +RTA = [\.0-9]+ ms
10
11[critical]
12$nullhost 0 0 0 0 -p 1 -to 1
13CRITICAL - Plugin timed out after 1 seconds
diff --git a/plugins/tests/check_procs b/plugins/tests/check_procs
deleted file mode 100644
index f7c65222..00000000
--- a/plugins/tests/check_procs
+++ /dev/null
@@ -1,23 +0,0 @@
1check_procs
2
3# this is a comment
4
5[normal]
6100000 100000
7^OK - [0-9]+ processes running$
8
9[normal]
10100000 100000 Z
11^OK - [0-9]+ processes with Z status$
12
13[warning]
140 10000000
15^WARNING - [0-9]+ processes running$
16
17[critical]
180 0
19^CRITICAL - [0-9]+ processes running$
20
21[critical]
220 0 S
23^CRITICAL - [0-9]+ processes with S status$
diff --git a/plugins/tests/check_swap b/plugins/tests/check_swap
deleted file mode 100644
index b6cbb42f..00000000
--- a/plugins/tests/check_swap
+++ /dev/null
@@ -1,13 +0,0 @@
1check_swap
2
3[normal]
4100 100
5^Swap ok - Swap used\: +[0-9]{1,2}\% \([0-9]+ bytes out of [0-9]+\)$
6
7[critical]
80 0
9^CRITICAL - Swap used\: +[0-9]{1,2}\% \([0-9]+ bytes out of [0-9]+\)$
10
11[critical]
12100 100 1000000000 10000000000
13^CRITICAL - Swap used\: +[0-9]{1,2}\% \([0-9]+ bytes out of [0-9]+\)$
diff --git a/plugins/tests/check_users b/plugins/tests/check_users
deleted file mode 100644
index 5a7959a5..00000000
--- a/plugins/tests/check_users
+++ /dev/null
@@ -1,9 +0,0 @@
1check_users
2
3[normal]
41000 1000
5^Users ok - +[0-9]+ users logged in$
6
7[critical]
80 0
9^[0-9]+ +users currently logged in$
diff --git a/plugins/tests/check_vsz b/plugins/tests/check_vsz
deleted file mode 100644
index 4fdec936..00000000
--- a/plugins/tests/check_vsz
+++ /dev/null
@@ -1,9 +0,0 @@
1check_vsz
2
3[normal]
4100000 1000000 init
5^ok \(all VSZ\<[0-9]+\)
6
7[critical]
80 0
9^CRITICAL \(VSZ\>[0-9]+\)
diff --git a/plugins/tests/test_utils.c b/plugins/tests/test_utils.c
new file mode 100644
index 00000000..1fda3675
--- /dev/null
+++ b/plugins/tests/test_utils.c
@@ -0,0 +1,109 @@
1/******************************************************************************
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
17 $Id$
18
19******************************************************************************/
20
21const char *progname = "utils";
22
23#include "common.h"
24#include "utils.h"
25#include "popen.h"
26
27#include "tap.h"
28
29int
30main (int argc, char **argv)
31{
32 threshold *range;
33 double temp;
34
35 plan_tests(40);
36
37 range = parse_threshold("6");
38 ok( range != NULL, "'6' is valid threshold");
39 ok( range->start == 0, "Start correct");
40 ok( range->start_infinity == FALSE, "Not using negative infinity");
41 ok( range->end == 6, "End correct");
42 ok( range->end_infinity == FALSE, "Not using infinity");
43 free(range);
44
45 range = parse_threshold("-7:23");
46 ok( range != NULL, "'-7:23' is valid threshold");
47 ok( range->start == -7, "Start correct");
48 ok( range->start_infinity == FALSE, "Not using negative infinity");
49 ok( range->end == 23, "End correct");
50 ok( range->end_infinity == FALSE, "Not using infinity");
51 free(range);
52
53 range = parse_threshold(":5.75");
54 ok( range != NULL, "':5.75' is valid threshold");
55 ok( range->start == 0, "Start correct");
56 ok( range->start_infinity == FALSE, "Not using negative infinity");
57 ok( range->end == 5.75, "End correct");
58 ok( range->end_infinity == FALSE, "Not using infinity");
59 free(range);
60
61 range = parse_threshold("~:-95.99");
62 ok( range != NULL, "~:-95.99' is valid threshold");
63 ok( range->start_infinity == TRUE, "Using negative infinity");
64 ok( range->end == -95.99, "End correct (with rounding errors)");
65 ok( range->end_infinity == FALSE, "Not using infinity");
66 free(range);
67
68 range = parse_threshold("12345678901234567890:");
69 temp = atof("12345678901234567890"); /* Can't just use this because number too large */
70 ok( range != NULL, "'12345678901234567890:' is valid threshold");
71 ok( range->start == temp, "Start correct");
72 ok( range->start_infinity == FALSE, "Not using negative infinity");
73 ok( range->end_infinity == TRUE, "Using infinity");
74 free(range);
75
76 range = parse_threshold("~:0");
77 ok( range != NULL, "'~:0' is valid threshold");
78 ok( range->start_infinity == TRUE, "Using negative infinity");
79 ok( range->end == 0, "End correct");
80 ok( range->end_infinity == FALSE, "Not using infinity");
81 ok( range->alert_on == OUTSIDE, "Will alert on outside of this range");
82 free(range);
83
84 range = parse_threshold("@0:657.8210567");
85 ok( range != 0, "@0:657.8210567' is a valid threshold");
86 ok( range->start == 0, "Start correct");
87 ok( range->start_infinity == FALSE, "Not using negative infinity");
88 ok( range->end == 657.8210567, "End correct");
89 ok( range->end_infinity == FALSE, "Not using infinity");
90 ok( range->alert_on == INSIDE, "Will alert on inside of this range" );
91 free(range);
92
93 range = parse_threshold("1:1");
94 ok( range != NULL, "'1:1' is a valid threshold");
95 ok( range->start == 1, "Start correct");
96 ok( range->start_infinity == FALSE, "Not using negative infinity");
97 ok( range->end == 1, "End correct");
98 ok( range->end_infinity == FALSE, "Not using infinity");
99 free(range);
100
101 range = parse_threshold("2:1");
102 ok( range == NULL, "''2:1' rejected");
103
104 return exit_status();
105}
106
107void print_usage() {
108 printf("Dummy");
109}
diff --git a/plugins/tests/test_utils.t b/plugins/tests/test_utils.t
new file mode 100755
index 00000000..8686ad2a
--- /dev/null
+++ b/plugins/tests/test_utils.t
@@ -0,0 +1,6 @@
1#!/usr/bin/perl
2use Test::More;
3if (! -e "./test_utils") {
4 plan skip_all => "./test_utils not compiled - check ./configure --with-libtap-object is defined";
5}
6exec "./test_utils";