From 2dec5182c508bd3cc286b4649836ead51aec50ef Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 19 Dec 2023 11:18:51 +0100 Subject: check_swap: refactor to improve readability --- plugins/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/Makefile.am') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 49086b7a..1ca7cf3f 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -107,7 +107,7 @@ check_real_LDADD = $(NETLIBS) check_snmp_LDADD = $(BASEOBJS) check_smtp_LDADD = $(SSLOBJS) check_ssh_LDADD = $(NETLIBS) -check_swap_LDADD = $(MATHLIBS) $(BASEOBJS) +check_swap_LDADD = $(MATHLIBS) $(BASEOBJS) check_swap.d/swap.o check_tcp_LDADD = $(SSLOBJS) check_time_LDADD = $(NETLIBS) check_ntp_time_LDADD = $(NETLIBS) $(MATHLIBS) -- cgit v1.2.3-74-g34f1 From 6fcbbaafc4bae79d4e674a2cf7f1d87d5a471603 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 19 Dec 2023 11:28:35 +0100 Subject: Implement first unit test for check_swap --- .gitignore | 2 ++ configure.ac | 3 +++ plugins/Makefile.am | 19 ++++++++++++++++--- plugins/tests/test_check_swap.c | 21 +++++++++++++++++++++ plugins/tests/test_check_swap.t | 6 ++++++ 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 plugins/tests/test_check_swap.c create mode 100644 plugins/tests/test_check_swap.t (limited to 'plugins/Makefile.am') diff --git a/.gitignore b/.gitignore index 7e640a0e..bbd7d844 100644 --- a/.gitignore +++ b/.gitignore @@ -221,7 +221,9 @@ NP-VERSION-FILE /plugins/tests/Makefile.in /plugins/tests/test_utils /plugins/tests/test_disk +/plugins/tests/test_check_swap /plugins/tests/.deps +/plugins/tests/.dirstamp # /plugins/check_swap.d /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 if test "$enable_libtap" = "yes" ; then EXTRA_TEST="test_utils test_disk test_tcp test_cmd test_base64" AC_SUBST(EXTRA_TEST) + + EXTRA_PLUGIN_TESTS="tests/test_check_swap" + AC_SUBST(EXTRA_PLUGIN_TESTS) fi 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 \ EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \ check_swap check_fping check_ldap check_game check_dig \ check_nagios check_by_ssh check_dns check_nt check_ide_smart \ - check_procs check_mysql_query check_apt check_dbi check_curl + check_procs check_mysql_query check_apt check_dbi check_curl \ + \ + tests/test_check_swap SUBDIRS = picohttpparser -EXTRA_DIST = t tests +np_test_scripts = tests/test_check_swap.t + +EXTRA_DIST = t tests $(np_test_scripts) PLUGINHDRS = common.h noinst_LIBRARIES = libnpcommon.a +noinst_PROGRAMS = @EXTRA_PLUGIN_TESTS@ +# These two lines support "make check", but we use "make test" +check_PROGRAMS = @EXTRA_PLUGIN_TESTS@ libnpcommon_a_SOURCES = utils.c netutils.c sslutils.c runcmd.c \ popen.c utils.h netutils.h popen.h common.h runcmd.c runcmd.h + BASEOBJS = libnpcommon.a ../lib/libmonitoringplug.a ../gl/libgnu.a $(LIB_CRYPTO) NETOBJS = $(BASEOBJS) $(EXTRA_NETOBLS) NETLIBS = $(NETOBJS) $(SOCKETLIBS) @@ -58,7 +66,10 @@ SSLOBJS = $(BASEOBJS) $(NETLIBS) $(SSLLIBS) $(LIB_CRYPTO) TESTS_ENVIRONMENT = perl -I $(top_builddir) -I $(top_srcdir) -TESTS = @PLUGIN_TEST@ +tap_ldflags = -L$(top_srcdir)/tap + +TESTS = @PLUGIN_TEST@ @EXTRA_PLUGIN_TESTS@ + test: perl -I $(top_builddir) -I $(top_srcdir) ../test.pl @@ -122,6 +133,8 @@ if !HAVE_UTMPX check_users_LDADD += popen.o endif +tests_test_check_swap_LDADD = $(BASEOBJS) check_swap.d/swap.o $(tap_ldflags) -ltap + ############################################################################## # secondary dependencies 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 @@ + +#include "../check_swap.d/check_swap.h" +#include "../../tap/tap.h" + +void print_usage() {}; +void print_help(swap_config config) { + (void) config; +}; + +const char *progname = "test_check_swap"; + +int main() { + + swap_config config = swap_config_init(); + + swap_result test_data = get_swap_data(config); + + plan_tests(1); + + ok(test_data.errorcode == 0, "Test whether we manage to retrieve swap data"); +} 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 @@ +#!/usr/bin/perl +use Test::More; +if (! -e "./test_check_swap") { + plan skip_all => "./test_swap not compiled - please enable libtap library to test"; +} +exec "./test_check_swap"; -- cgit v1.2.3-74-g34f1 From fc9caba617cac02a205fb63b87b08fbc5c6a2955 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 19 Dec 2023 14:34:05 +0100 Subject: Hopefully fix build --- plugins/Makefile.am | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'plugins/Makefile.am') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 8ef2a246..0a720b2d 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -118,7 +118,8 @@ check_real_LDADD = $(NETLIBS) check_snmp_LDADD = $(BASEOBJS) check_smtp_LDADD = $(SSLOBJS) check_ssh_LDADD = $(NETLIBS) -check_swap_LDADD = $(MATHLIBS) $(BASEOBJS) check_swap.d/swap.o +check_swap_SOURCES = check_swap.c check_swap.d/swap.c +check_swap_LDADD = $(MATHLIBS) $(BASEOBJS) check_tcp_LDADD = $(SSLOBJS) check_time_LDADD = $(NETLIBS) check_ntp_time_LDADD = $(NETLIBS) $(MATHLIBS) @@ -133,7 +134,8 @@ if !HAVE_UTMPX check_users_LDADD += popen.o endif -tests_test_check_swap_LDADD = $(BASEOBJS) check_swap.d/swap.o $(tap_ldflags) -ltap +tests_test_check_swap_LDADD = $(BASEOBJS) $(tap_ldflags) -ltap +tests_test_check_swap_SOURCES = check_swap.c check_swap.d/swap.c ############################################################################## # secondary dependencies -- cgit v1.2.3-74-g34f1 From 9083896d9c5f5a06f4f0c7c356879dc32330dab7 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 19 Dec 2023 14:48:01 +0100 Subject: Include new directory and contents into distribution --- plugins/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/Makefile.am') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 0a720b2d..2310f107 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -46,7 +46,7 @@ SUBDIRS = picohttpparser np_test_scripts = tests/test_check_swap.t -EXTRA_DIST = t tests $(np_test_scripts) +EXTRA_DIST = t tests $(np_test_scripts) check_swap.d PLUGINHDRS = common.h -- cgit v1.2.3-74-g34f1 From 1d669e47eb9e6971b266d451274c02c5203b1906 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Thu, 4 Jan 2024 02:36:50 +0100 Subject: Fix Makefile.am to fix tests --- plugins/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/Makefile.am') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 2310f107..d43c1971 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -135,7 +135,7 @@ check_users_LDADD += popen.o endif tests_test_check_swap_LDADD = $(BASEOBJS) $(tap_ldflags) -ltap -tests_test_check_swap_SOURCES = check_swap.c check_swap.d/swap.c +tests_test_check_swap_SOURCES = tests/test_check_swap.c check_swap.d/swap.c ############################################################################## # secondary dependencies -- cgit v1.2.3-74-g34f1