summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2023-12-19 11:28:35 +0100
committerRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2023-12-20 10:02:47 +0100
commit6fcbbaafc4bae79d4e674a2cf7f1d87d5a471603 (patch)
treebcce5da6a2b96b7f288d948db0584fe8420ce824
parent2dec5182c508bd3cc286b4649836ead51aec50ef (diff)
downloadmonitoring-plugins-6fcbbaafc4bae79d4e674a2cf7f1d87d5a471603.tar.gz
Implement first unit test for check_swap
-rw-r--r--.gitignore2
-rw-r--r--configure.ac3
-rw-r--r--plugins/Makefile.am19
-rw-r--r--plugins/tests/test_check_swap.c21
-rw-r--r--plugins/tests/test_check_swap.t6
5 files changed, 48 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index 7e640a0e..bbd7d844 100644
--- a/.gitignore
+++ b/.gitignore
@@ -221,7 +221,9 @@ NP-VERSION-FILE
221/plugins/tests/Makefile.in 221/plugins/tests/Makefile.in
222/plugins/tests/test_utils 222/plugins/tests/test_utils
223/plugins/tests/test_disk 223/plugins/tests/test_disk
224/plugins/tests/test_check_swap
224/plugins/tests/.deps 225/plugins/tests/.deps
226/plugins/tests/.dirstamp
225 227
226# /plugins/check_swap.d 228# /plugins/check_swap.d
227/plugins/check_swap.d/.deps 229/plugins/check_swap.d/.deps
diff --git a/configure.ac b/configure.ac
index 42fc0292..190b43ad 100644
--- a/configure.ac
+++ b/configure.ac
@@ -185,6 +185,9 @@ fi
185if test "$enable_libtap" = "yes" ; then 185if test "$enable_libtap" = "yes" ; then
186 EXTRA_TEST="test_utils test_disk test_tcp test_cmd test_base64" 186 EXTRA_TEST="test_utils test_disk test_tcp test_cmd test_base64"
187 AC_SUBST(EXTRA_TEST) 187 AC_SUBST(EXTRA_TEST)
188
189 EXTRA_PLUGIN_TESTS="tests/test_check_swap"
190 AC_SUBST(EXTRA_PLUGIN_TESTS)
188fi 191fi
189 192
190dnl INI Parsing 193dnl INI Parsing
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 1ca7cf3f..8ef2a246 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -38,19 +38,27 @@ check_tcp_programs = check_ftp check_imap check_nntp check_pop \
38EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \ 38EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \
39 check_swap check_fping check_ldap check_game check_dig \ 39 check_swap check_fping check_ldap check_game check_dig \
40 check_nagios check_by_ssh check_dns check_nt check_ide_smart \ 40 check_nagios check_by_ssh check_dns check_nt check_ide_smart \
41 check_procs check_mysql_query check_apt check_dbi check_curl 41 check_procs check_mysql_query check_apt check_dbi check_curl \
42 \
43 tests/test_check_swap
42 44
43SUBDIRS = picohttpparser 45SUBDIRS = picohttpparser
44 46
45EXTRA_DIST = t tests 47np_test_scripts = tests/test_check_swap.t
48
49EXTRA_DIST = t tests $(np_test_scripts)
46 50
47PLUGINHDRS = common.h 51PLUGINHDRS = common.h
48 52
49noinst_LIBRARIES = libnpcommon.a 53noinst_LIBRARIES = libnpcommon.a
54noinst_PROGRAMS = @EXTRA_PLUGIN_TESTS@
55# These two lines support "make check", but we use "make test"
56check_PROGRAMS = @EXTRA_PLUGIN_TESTS@
50 57
51libnpcommon_a_SOURCES = utils.c netutils.c sslutils.c runcmd.c \ 58libnpcommon_a_SOURCES = utils.c netutils.c sslutils.c runcmd.c \
52 popen.c utils.h netutils.h popen.h common.h runcmd.c runcmd.h 59 popen.c utils.h netutils.h popen.h common.h runcmd.c runcmd.h
53 60
61
54BASEOBJS = libnpcommon.a ../lib/libmonitoringplug.a ../gl/libgnu.a $(LIB_CRYPTO) 62BASEOBJS = libnpcommon.a ../lib/libmonitoringplug.a ../gl/libgnu.a $(LIB_CRYPTO)
55NETOBJS = $(BASEOBJS) $(EXTRA_NETOBLS) 63NETOBJS = $(BASEOBJS) $(EXTRA_NETOBLS)
56NETLIBS = $(NETOBJS) $(SOCKETLIBS) 64NETLIBS = $(NETOBJS) $(SOCKETLIBS)
@@ -58,7 +66,10 @@ SSLOBJS = $(BASEOBJS) $(NETLIBS) $(SSLLIBS) $(LIB_CRYPTO)
58 66
59TESTS_ENVIRONMENT = perl -I $(top_builddir) -I $(top_srcdir) 67TESTS_ENVIRONMENT = perl -I $(top_builddir) -I $(top_srcdir)
60 68
61TESTS = @PLUGIN_TEST@ 69tap_ldflags = -L$(top_srcdir)/tap
70
71TESTS = @PLUGIN_TEST@ @EXTRA_PLUGIN_TESTS@
72
62 73
63test: 74test:
64 perl -I $(top_builddir) -I $(top_srcdir) ../test.pl 75 perl -I $(top_builddir) -I $(top_srcdir) ../test.pl
@@ -122,6 +133,8 @@ if !HAVE_UTMPX
122check_users_LDADD += popen.o 133check_users_LDADD += popen.o
123endif 134endif
124 135
136tests_test_check_swap_LDADD = $(BASEOBJS) check_swap.d/swap.o $(tap_ldflags) -ltap
137
125############################################################################## 138##############################################################################
126# secondary dependencies 139# secondary dependencies
127 140
diff --git a/plugins/tests/test_check_swap.c b/plugins/tests/test_check_swap.c
new file mode 100644
index 00000000..42ac0086
--- /dev/null
+++ b/plugins/tests/test_check_swap.c
@@ -0,0 +1,21 @@
1
2#include "../check_swap.d/check_swap.h"
3#include "../../tap/tap.h"
4
5void print_usage() {};
6void print_help(swap_config config) {
7 (void) config;
8};
9
10const char *progname = "test_check_swap";
11
12int main() {
13
14 swap_config config = swap_config_init();
15
16 swap_result test_data = get_swap_data(config);
17
18 plan_tests(1);
19
20 ok(test_data.errorcode == 0, "Test whether we manage to retrieve swap data");
21}
diff --git a/plugins/tests/test_check_swap.t b/plugins/tests/test_check_swap.t
new file mode 100644
index 00000000..97c651a8
--- /dev/null
+++ b/plugins/tests/test_check_swap.t
@@ -0,0 +1,6 @@
1#!/usr/bin/perl
2use Test::More;
3if (! -e "./test_check_swap") {
4 plan skip_all => "./test_swap not compiled - please enable libtap library to test";
5}
6exec "./test_check_swap";