summaryrefslogtreecommitdiffstats
path: root/lib/tests
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tests')
-rw-r--r--lib/tests/Makefile.am2
-rwxr-xr-xlib/tests/test_base64.t2
-rw-r--r--lib/tests/test_cmd.t2
-rwxr-xr-xlib/tests/test_disk.t2
-rwxr-xr-xlib/tests/test_ini1.t2
-rwxr-xr-xlib/tests/test_ini3.t2
-rwxr-xr-xlib/tests/test_opts1.t2
-rwxr-xr-xlib/tests/test_opts2.t2
-rwxr-xr-xlib/tests/test_opts3.t2
-rwxr-xr-xlib/tests/test_tcp.t2
-rw-r--r--lib/tests/test_utils.c58
-rwxr-xr-xlib/tests/test_utils.t2
12 files changed, 41 insertions, 39 deletions
diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am
index 1af5891..c0411ac 100644
--- a/lib/tests/Makefile.am
+++ b/lib/tests/Makefile.am
@@ -28,7 +28,7 @@ endif
28 28
29AM_CFLAGS = -g -I$(top_srcdir)/lib -I$(top_srcdir)/gl $(tap_cflags) 29AM_CFLAGS = -g -I$(top_srcdir)/lib -I$(top_srcdir)/gl $(tap_cflags)
30AM_LDFLAGS = $(tap_ldflags) -ltap 30AM_LDFLAGS = $(tap_ldflags) -ltap
31LDADD = $(top_srcdir)/lib/libnagiosplug.a $(top_srcdir)/gl/libgnu.a 31LDADD = $(top_srcdir)/lib/libmonitoringplug.a $(top_srcdir)/gl/libgnu.a
32 32
33SOURCES = test_utils.c test_disk.c test_tcp.c test_cmd.c test_base64.c test_ini1.c test_ini3.c test_opts1.c test_opts2.c test_opts3.c 33SOURCES = test_utils.c test_disk.c test_tcp.c test_cmd.c test_base64.c test_ini1.c test_ini3.c test_opts1.c test_opts2.c test_opts3.c
34 34
diff --git a/lib/tests/test_base64.t b/lib/tests/test_base64.t
index 4b9236f..4ad6473 100755
--- a/lib/tests/test_base64.t
+++ b/lib/tests/test_base64.t
@@ -1,6 +1,6 @@
1#!/usr/bin/perl 1#!/usr/bin/perl
2use Test::More; 2use Test::More;
3if (! -e "./test_base64") { 3if (! -e "./test_base64") {
4 plan skip_all => "./test_base64 not compiled - please install tap library to test"; 4 plan skip_all => "./test_base64 not compiled - please enable libtap library to test";
5} 5}
6exec "./test_base64"; 6exec "./test_base64";
diff --git a/lib/tests/test_cmd.t b/lib/tests/test_cmd.t
index 4dd54ef..c50dded 100644
--- a/lib/tests/test_cmd.t
+++ b/lib/tests/test_cmd.t
@@ -1,6 +1,6 @@
1#!/usr/bin/perl 1#!/usr/bin/perl
2use Test::More; 2use Test::More;
3if (! -e "./test_cmd") { 3if (! -e "./test_cmd") {
4 plan skip_all => "./test_cmd not compiled - please install tap library to test"; 4 plan skip_all => "./test_cmd not compiled - please enable libtap library to test";
5} 5}
6exec "./test_cmd"; 6exec "./test_cmd";
diff --git a/lib/tests/test_disk.t b/lib/tests/test_disk.t
index d32567a..da84dfd 100755
--- a/lib/tests/test_disk.t
+++ b/lib/tests/test_disk.t
@@ -1,6 +1,6 @@
1#!/usr/bin/perl 1#!/usr/bin/perl
2use Test::More; 2use Test::More;
3if (! -e "./test_disk") { 3if (! -e "./test_disk") {
4 plan skip_all => "./test_disk not compiled - please install tap library to test"; 4 plan skip_all => "./test_disk not compiled - please enable libtap library to test";
5} 5}
6exec "./test_disk"; 6exec "./test_disk";
diff --git a/lib/tests/test_ini1.t b/lib/tests/test_ini1.t
index d481011..25baed9 100755
--- a/lib/tests/test_ini1.t
+++ b/lib/tests/test_ini1.t
@@ -1,6 +1,6 @@
1#!/usr/bin/perl 1#!/usr/bin/perl
2use Test::More; 2use Test::More;
3if (! -e "./test_ini1") { 3if (! -e "./test_ini1") {
4 plan skip_all => "./test_ini not compiled - please install tap library and/or enable parse-ini to test"; 4 plan skip_all => "./test_ini not compiled - please enable libtap library and/or extra-opts to test";
5} 5}
6exec "./test_ini1"; 6exec "./test_ini1";
diff --git a/lib/tests/test_ini3.t b/lib/tests/test_ini3.t
index 4b0be4c..a2ca94a 100755
--- a/lib/tests/test_ini3.t
+++ b/lib/tests/test_ini3.t
@@ -4,7 +4,7 @@ use strict;
4use warnings; 4use warnings;
5 5
6if (! -e "./test_ini3") { 6if (! -e "./test_ini3") {
7 plan skip_all => "./test_ini not compiled - please install tap library and/or enable parse-ini to test"; 7 plan skip_all => "./test_ini not compiled - please enable libtap library and/or extra-opts to test";
8} 8}
9 9
10# array of argument arrays 10# array of argument arrays
diff --git a/lib/tests/test_opts1.t b/lib/tests/test_opts1.t
index 52eed94..1934f12 100755
--- a/lib/tests/test_opts1.t
+++ b/lib/tests/test_opts1.t
@@ -1,6 +1,6 @@
1#!/usr/bin/perl 1#!/usr/bin/perl
2use Test::More; 2use Test::More;
3if (! -e "./test_opts1") { 3if (! -e "./test_opts1") {
4 plan skip_all => "./test_opts1 not compiled - please install tap library and/or enable parse-ini to test"; 4 plan skip_all => "./test_opts1 not compiled - please enable libtap library and/or extra-opts to test";
5} 5}
6exec "./test_opts1"; 6exec "./test_opts1";
diff --git a/lib/tests/test_opts2.t b/lib/tests/test_opts2.t
index f7444f6..59b9fdb 100755
--- a/lib/tests/test_opts2.t
+++ b/lib/tests/test_opts2.t
@@ -1,7 +1,7 @@
1#!/usr/bin/perl 1#!/usr/bin/perl
2use Test::More; 2use Test::More;
3if (! -e "./test_opts2") { 3if (! -e "./test_opts2") {
4 plan skip_all => "./test_opts2 not compiled - please install tap library and/or enable parse-ini to test"; 4 plan skip_all => "./test_opts2 not compiled - please enable libtap library and/or extra-opts to test";
5} 5}
6$ENV{"NAGIOS_CONFIG_PATH"} = "."; 6$ENV{"NAGIOS_CONFIG_PATH"} = ".";
7exec "./test_opts2"; 7exec "./test_opts2";
diff --git a/lib/tests/test_opts3.t b/lib/tests/test_opts3.t
index fa7876d..8d974ca 100755
--- a/lib/tests/test_opts3.t
+++ b/lib/tests/test_opts3.t
@@ -4,7 +4,7 @@ use strict;
4use warnings; 4use warnings;
5 5
6if (! -e "./test_opts3") { 6if (! -e "./test_opts3") {
7 plan skip_all => "./test_opts3 not compiled - please install tap library and/or enable parse-ini to test"; 7 plan skip_all => "./test_opts3 not compiled - please enable libtap library and/or extra-opts to test";
8} 8}
9 9
10# array of argument arrays 10# array of argument arrays
diff --git a/lib/tests/test_tcp.t b/lib/tests/test_tcp.t
index 8f34b67..e5e12fc 100755
--- a/lib/tests/test_tcp.t
+++ b/lib/tests/test_tcp.t
@@ -1,6 +1,6 @@
1#!/usr/bin/perl 1#!/usr/bin/perl
2use Test::More; 2use Test::More;
3if (! -e "./test_tcp") { 3if (! -e "./test_tcp") {
4 plan skip_all => "./test_tcp not compiled - please install tap library to test"; 4 plan skip_all => "./test_tcp not compiled - please enable libtap library to test";
5} 5}
6exec "./test_tcp"; 6exec "./test_tcp";
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c
index 79e1110..0571340 100644
--- a/lib/tests/test_utils.c
+++ b/lib/tests/test_utils.c
@@ -38,22 +38,22 @@ main (int argc, char **argv)
38 state_data *temp_state_data; 38 state_data *temp_state_data;
39 time_t current_time; 39 time_t current_time;
40 40
41 plan_tests(150); 41 plan_tests(151);
42 42
43 ok( this_nagios_plugin==NULL, "nagios_plugin not initialised"); 43 ok( this_monitoring_plugin==NULL, "monitoring_plugin not initialised");
44 44
45 np_init( "check_test", argc, argv ); 45 np_init( "check_test", argc, argv );
46 46
47 ok( this_nagios_plugin!=NULL, "nagios_plugin now initialised"); 47 ok( this_monitoring_plugin!=NULL, "monitoring_plugin now initialised");
48 ok( !strcmp(this_nagios_plugin->plugin_name, "check_test"), "plugin name initialised" ); 48 ok( !strcmp(this_monitoring_plugin->plugin_name, "check_test"), "plugin name initialised" );
49 49
50 ok( this_nagios_plugin->argc==argc, "Argc set" ); 50 ok( this_monitoring_plugin->argc==argc, "Argc set" );
51 ok( this_nagios_plugin->argv==argv, "Argv set" ); 51 ok( this_monitoring_plugin->argv==argv, "Argv set" );
52 52
53 np_set_args(0,0); 53 np_set_args(0,0);
54 54
55 ok( this_nagios_plugin->argc==0, "argc changed" ); 55 ok( this_monitoring_plugin->argc==0, "argc changed" );
56 ok( this_nagios_plugin->argv==0, "argv changed" ); 56 ok( this_monitoring_plugin->argv==0, "argv changed" );
57 57
58 np_set_args(argc, argv); 58 np_set_args(argc, argv);
59 59
@@ -296,23 +296,23 @@ main (int argc, char **argv)
296 diag( "You are probably running in wrong directory. Must run as ./test_utils" ); 296 diag( "You are probably running in wrong directory. Must run as ./test_utils" );
297 297
298 298
299 this_nagios_plugin->argc=4; 299 this_monitoring_plugin->argc=4;
300 this_nagios_plugin->argv[0] = "./test_utils"; 300 this_monitoring_plugin->argv[0] = "./test_utils";
301 this_nagios_plugin->argv[1] = "here"; 301 this_monitoring_plugin->argv[1] = "here";
302 this_nagios_plugin->argv[2] = "--and"; 302 this_monitoring_plugin->argv[2] = "--and";
303 this_nagios_plugin->argv[3] = "now"; 303 this_monitoring_plugin->argv[3] = "now";
304 temp_string = (char *) _np_state_generate_key(); 304 temp_string = (char *) _np_state_generate_key();
305 ok(!strcmp(temp_string, "94b5e17bf5abf51cb15aff5f69b96f2f8dac5ecd"), "Got based on expected argv" ); 305 ok(!strcmp(temp_string, "94b5e17bf5abf51cb15aff5f69b96f2f8dac5ecd"), "Got based on expected argv" );
306 306
307 unsetenv("NAGIOS_PLUGIN_STATE_DIRECTORY"); 307 unsetenv("MP_STATE_PATH");
308 temp_string = (char *) _np_state_calculate_location_prefix(); 308 temp_string = (char *) _np_state_calculate_location_prefix();
309 ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory" ); 309 ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory" );
310 310
311 setenv("NAGIOS_PLUGIN_STATE_DIRECTORY", "", 1); 311 setenv("MP_STATE_PATH", "", 1);
312 temp_string = (char *) _np_state_calculate_location_prefix(); 312 temp_string = (char *) _np_state_calculate_location_prefix();
313 ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory even with empty string" ); 313 ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory even with empty string" );
314 314
315 setenv("NAGIOS_PLUGIN_STATE_DIRECTORY", "/usr/local/nagios/var", 1); 315 setenv("MP_STATE_PATH", "/usr/local/nagios/var", 1);
316 temp_string = (char *) _np_state_calculate_location_prefix(); 316 temp_string = (char *) _np_state_calculate_location_prefix();
317 ok(!strcmp(temp_string, "/usr/local/nagios/var"), "Got default directory" ); 317 ok(!strcmp(temp_string, "/usr/local/nagios/var"), "Got default directory" );
318 318
@@ -320,16 +320,16 @@ main (int argc, char **argv)
320 320
321 ok(temp_state_key==NULL, "temp_state_key initially empty"); 321 ok(temp_state_key==NULL, "temp_state_key initially empty");
322 322
323 this_nagios_plugin->argc=1; 323 this_monitoring_plugin->argc=1;
324 this_nagios_plugin->argv[0] = "./test_utils"; 324 this_monitoring_plugin->argv[0] = "./test_utils";
325 np_enable_state(NULL, 51); 325 np_enable_state(NULL, 51);
326 temp_state_key = this_nagios_plugin->state; 326 temp_state_key = this_monitoring_plugin->state;
327 ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); 327 ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" );
328 ok( !strcmp(temp_state_key->name, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got generated filename" ); 328 ok( !strcmp(temp_state_key->name, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got generated filename" );
329 329
330 330
331 np_enable_state("allowedchars_in_keyname", 77); 331 np_enable_state("allowedchars_in_keyname", 77);
332 temp_state_key = this_nagios_plugin->state; 332 temp_state_key = this_monitoring_plugin->state;
333 ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); 333 ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" );
334 ok( !strcmp(temp_state_key->name, "allowedchars_in_keyname"), "Got key name with valid chars" ); 334 ok( !strcmp(temp_state_key->name, "allowedchars_in_keyname"), "Got key name with valid chars" );
335 ok( !strcmp(temp_state_key->_filename, "/usr/local/nagios/var/check_test/allowedchars_in_keyname"), "Got internal filename" ); 335 ok( !strcmp(temp_state_key->_filename, "/usr/local/nagios/var/check_test/allowedchars_in_keyname"), "Got internal filename" );
@@ -338,12 +338,12 @@ main (int argc, char **argv)
338 /* Don't do this test just yet. Will die */ 338 /* Don't do this test just yet. Will die */
339 /* 339 /*
340 np_enable_state("bad^chars$in@here", 77); 340 np_enable_state("bad^chars$in@here", 77);
341 temp_state_key = this_nagios_plugin->state; 341 temp_state_key = this_monitoring_plugin->state;
342 ok( !strcmp(temp_state_key->name, "bad_chars_in_here"), "Got key name with bad chars replaced" ); 342 ok( !strcmp(temp_state_key->name, "bad_chars_in_here"), "Got key name with bad chars replaced" );
343 */ 343 */
344 344
345 np_enable_state("funnykeyname", 54); 345 np_enable_state("funnykeyname", 54);
346 temp_state_key = this_nagios_plugin->state; 346 temp_state_key = this_monitoring_plugin->state;
347 ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); 347 ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" );
348 ok( !strcmp(temp_state_key->name, "funnykeyname"), "Got key name" ); 348 ok( !strcmp(temp_state_key->name, "funnykeyname"), "Got key name" );
349 349
@@ -367,9 +367,9 @@ main (int argc, char **argv)
367 367
368 temp_state_key->_filename="var/statefile"; 368 temp_state_key->_filename="var/statefile";
369 temp_state_data = np_state_read(); 369 temp_state_data = np_state_read();
370 ok( this_nagios_plugin->state->state_data!=NULL, "Got state data now" ) || diag("Are you running in right directory? Will get coredump next if not"); 370 ok( this_monitoring_plugin->state->state_data!=NULL, "Got state data now" ) || diag("Are you running in right directory? Will get coredump next if not");
371 ok( this_nagios_plugin->state->state_data->time==1234567890, "Got time" ); 371 ok( this_monitoring_plugin->state->state_data->time==1234567890, "Got time" );
372 ok( !strcmp((char *)this_nagios_plugin->state->state_data->data, "String to read"), "Data as expected" ); 372 ok( !strcmp((char *)this_monitoring_plugin->state->state_data->data, "String to read"), "Data as expected" );
373 373
374 temp_state_key->data_version=53; 374 temp_state_key->data_version=53;
375 temp_state_data = np_state_read(); 375 temp_state_data = np_state_read();
@@ -379,7 +379,7 @@ main (int argc, char **argv)
379 temp_state_key->_filename="var/nonexistant"; 379 temp_state_key->_filename="var/nonexistant";
380 temp_state_data = np_state_read(); 380 temp_state_data = np_state_read();
381 ok( temp_state_data==NULL, "Missing file gives NULL" ); 381 ok( temp_state_data==NULL, "Missing file gives NULL" );
382 ok( this_nagios_plugin->state->state_data==NULL, "No state information" ); 382 ok( this_monitoring_plugin->state->state_data==NULL, "No state information" );
383 383
384 temp_state_key->_filename="var/oldformat"; 384 temp_state_key->_filename="var/oldformat";
385 temp_state_data = np_state_read(); 385 temp_state_data = np_state_read();
@@ -426,7 +426,7 @@ main (int argc, char **argv)
426 temp_state_data = np_state_read(); 426 temp_state_data = np_state_read();
427 /* Check time is set to current_time */ 427 /* Check time is set to current_time */
428 ok(system("cmp var/generated var/statefile > /dev/null")!=0, "Generated file should be different this time"); 428 ok(system("cmp var/generated var/statefile > /dev/null")!=0, "Generated file should be different this time");
429 ok(this_nagios_plugin->state->state_data->time-current_time<=1, "Has time generated from current time"); 429 ok(this_monitoring_plugin->state->state_data->time-current_time<=1, "Has time generated from current time");
430 430
431 431
432 /* Don't know how to automatically test this. Need to be able to redefine die and catch the error */ 432 /* Don't know how to automatically test this. Need to be able to redefine die and catch the error */
@@ -438,7 +438,9 @@ main (int argc, char **argv)
438 438
439 np_cleanup(); 439 np_cleanup();
440 440
441 ok( this_nagios_plugin==NULL, "Free'd this_nagios_plugin" ); 441 ok( this_monitoring_plugin==NULL, "Free'd this_monitoring_plugin" );
442
443 ok( mp_suid() == FALSE, "test aren't suid" );
442 444
443 return exit_status(); 445 return exit_status();
444} 446}
diff --git a/lib/tests/test_utils.t b/lib/tests/test_utils.t
index 152eb71..e2a9311 100755
--- a/lib/tests/test_utils.t
+++ b/lib/tests/test_utils.t
@@ -1,6 +1,6 @@
1#!/usr/bin/perl 1#!/usr/bin/perl
2use Test::More; 2use Test::More;
3if (! -e "./test_utils") { 3if (! -e "./test_utils") {
4 plan skip_all => "./test_utils not compiled - please install tap library to test"; 4 plan skip_all => "./test_utils not compiled - please enable libtap library to test";
5} 5}
6exec "./test_utils"; 6exec "./test_utils";