diff options
| author | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-12-19 11:28:35 +0100 |
|---|---|---|
| committer | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-12-20 10:02:47 +0100 |
| commit | 6fcbbaafc4bae79d4e674a2cf7f1d87d5a471603 (patch) | |
| tree | bcce5da6a2b96b7f288d948db0584fe8420ce824 | |
| parent | 2dec5182c508bd3cc286b4649836ead51aec50ef (diff) | |
| download | monitoring-plugins-6fcbbaafc4bae79d4e674a2cf7f1d87d5a471603.tar.gz | |
Implement first unit test for check_swap
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | configure.ac | 3 | ||||
| -rw-r--r-- | plugins/Makefile.am | 19 | ||||
| -rw-r--r-- | plugins/tests/test_check_swap.c | 21 | ||||
| -rw-r--r-- | plugins/tests/test_check_swap.t | 6 |
5 files changed, 48 insertions, 3 deletions
| @@ -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 | |||
| 185 | if test "$enable_libtap" = "yes" ; then | 185 | if 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) | ||
| 188 | fi | 191 | fi |
| 189 | 192 | ||
| 190 | dnl INI Parsing | 193 | dnl 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 \ | |||
| 38 | EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \ | 38 | EXTRA_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 | ||
| 43 | SUBDIRS = picohttpparser | 45 | SUBDIRS = picohttpparser |
| 44 | 46 | ||
| 45 | EXTRA_DIST = t tests | 47 | np_test_scripts = tests/test_check_swap.t |
| 48 | |||
| 49 | EXTRA_DIST = t tests $(np_test_scripts) | ||
| 46 | 50 | ||
| 47 | PLUGINHDRS = common.h | 51 | PLUGINHDRS = common.h |
| 48 | 52 | ||
| 49 | noinst_LIBRARIES = libnpcommon.a | 53 | noinst_LIBRARIES = libnpcommon.a |
| 54 | noinst_PROGRAMS = @EXTRA_PLUGIN_TESTS@ | ||
| 55 | # These two lines support "make check", but we use "make test" | ||
| 56 | check_PROGRAMS = @EXTRA_PLUGIN_TESTS@ | ||
| 50 | 57 | ||
| 51 | libnpcommon_a_SOURCES = utils.c netutils.c sslutils.c runcmd.c \ | 58 | libnpcommon_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 | |||
| 54 | BASEOBJS = libnpcommon.a ../lib/libmonitoringplug.a ../gl/libgnu.a $(LIB_CRYPTO) | 62 | BASEOBJS = libnpcommon.a ../lib/libmonitoringplug.a ../gl/libgnu.a $(LIB_CRYPTO) |
| 55 | NETOBJS = $(BASEOBJS) $(EXTRA_NETOBLS) | 63 | NETOBJS = $(BASEOBJS) $(EXTRA_NETOBLS) |
| 56 | NETLIBS = $(NETOBJS) $(SOCKETLIBS) | 64 | NETLIBS = $(NETOBJS) $(SOCKETLIBS) |
| @@ -58,7 +66,10 @@ SSLOBJS = $(BASEOBJS) $(NETLIBS) $(SSLLIBS) $(LIB_CRYPTO) | |||
| 58 | 66 | ||
| 59 | TESTS_ENVIRONMENT = perl -I $(top_builddir) -I $(top_srcdir) | 67 | TESTS_ENVIRONMENT = perl -I $(top_builddir) -I $(top_srcdir) |
| 60 | 68 | ||
| 61 | TESTS = @PLUGIN_TEST@ | 69 | tap_ldflags = -L$(top_srcdir)/tap |
| 70 | |||
| 71 | TESTS = @PLUGIN_TEST@ @EXTRA_PLUGIN_TESTS@ | ||
| 72 | |||
| 62 | 73 | ||
| 63 | test: | 74 | test: |
| 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 | |||
| 122 | check_users_LDADD += popen.o | 133 | check_users_LDADD += popen.o |
| 123 | endif | 134 | endif |
| 124 | 135 | ||
| 136 | tests_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 | |||
| 5 | void print_usage() {}; | ||
| 6 | void print_help(swap_config config) { | ||
| 7 | (void) config; | ||
| 8 | }; | ||
| 9 | |||
| 10 | const char *progname = "test_check_swap"; | ||
| 11 | |||
| 12 | int 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 | ||
| 2 | use Test::More; | ||
| 3 | if (! -e "./test_check_swap") { | ||
| 4 | plan skip_all => "./test_swap not compiled - please enable libtap library to test"; | ||
| 5 | } | ||
| 6 | exec "./test_check_swap"; | ||
