Skip to content

Commit

Permalink
tests: Add a test the checks ack expiry - WIP
Browse files Browse the repository at this point in the history
A new test file, intended to contain tests that process the event queue
and check the results.

The first test in it checks if the acknowledgement expiry event does its
work.
  • Loading branch information
roelvanmeer committed Sep 6, 2022
1 parent f37e375 commit 7dc5bbf
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 1 deletion.
129 changes: 129 additions & 0 deletions t-tap/test_events.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*****************************************************************************
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*****************************************************************************/
#include <string.h>
#include <assert.h>
#include "tap.h"
#include "naemon/objects.h"
#include "naemon/commands.h"
#include "naemon/downtime.h"
#include "naemon/comments.h"
#include "naemon/globals.h"
#include "naemon/utils.h"
#include "naemon/configuration.h"
#include "naemon/defaults.h"
#include "naemon/sretention.h"
#include "naemon/events.h"

static int *received_persistent;
static char *received_host;
static time_t received_entry_time;
char *addresses[2];
timeperiod *registered_timeperiod = NULL;
int b_val;
int i_val;
time_t t_val;
GError *error = NULL;
char *s_val;


int test__add_host_comment_handler(const struct external_command *ext_command, time_t entry_time)
{
command_argument_value_copy((void **) &received_host, command_argument_get_value(ext_command, "host"), STRING);
command_argument_value_copy((void **) &received_persistent, command_argument_get_value(ext_command, "persistent"), BOOL);
received_entry_time = entry_time;
return 0;
}
int test__add_service_comment_handler(const struct external_command *ext_command, time_t entry_time)
{
return 0;
}

int test__del_host_comment_handler(const struct external_command *ext_command, time_t entry_time)
{
return 0;
}

int test__disable_notifications_handler(const struct external_command *ext_command, time_t entry_time)
{
return 0;
}

int test__do_thing_with_timeperiod_handler(const struct external_command *ext_command, time_t entry_time)
{
return 0;
}


int test__do_thing_with_contact_handler(const struct external_command *ext_command, time_t entry_time)
{
return 0;
}
int custom_service_validator(void *value)
{
return 1;
}

void test_host_commands(void)
{
char *host_name = "host1";
host *target_host = NULL;
time_t current_time = 0;
char *cmdstr = NULL;
target_host = find_host(host_name);
target_host->obsess = FALSE;

target_host->current_state = STATE_DOWN;
time(&current_time);
nm_asprintf(&cmdstr, "[1234567890] ACKNOWLEDGE_HOST_PROBLEM_EXPIRE;host1;2;0;0;%llu;myself;expire in two seconds", (unsigned long long int)current_time+2);
ok(CMD_ERROR_OK == process_external_command1(cmdstr), "core command: ACKNOWLEDGE_HOST_PROBLEM_EXPIRE");
ok(target_host->problem_has_been_acknowledged, "ACKNOWLEDGE_HOST_PROBLEM_EXPIRE acknowledgement present before event");
sleep(3);
/* This should be done better. How do we know how many
events we have to process? */
event_poll();
event_poll();
ok(!target_host->problem_has_been_acknowledged, "ACKNOWLEDGE_HOST_PROBLEM_EXPIRE acknowledgement gone after event");
free(cmdstr);
}

void test_core_commands(void)
{
/*setup configuration*/
pre_flight_check(); /*without this, child_host links are not created and *_BEYOND_HOST test cases fail...*/
registered_commands_init(200);
register_core_commands();
test_host_commands();
registered_commands_deinit();
free(config_file);
}

int main(int /*@unused@*/ argc, char /*@unused@*/ **arv)
{
const char *test_config_file = TESTDIR "naemon.cfg";
plan_tests(3);
init_event_queue();

config_file_dir = nspath_absolute_dirname(test_config_file, NULL);
assert(OK == read_main_config_file(test_config_file));
assert(OK == read_all_object_data(test_config_file));
assert(OK == initialize_downtime_data());
assert(OK == initialize_retention_data());
nagios_iobs = iobroker_create();
test_core_commands();
return exit_status();
}
7 changes: 6 additions & 1 deletion tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ t_tap_test_downtime_SOURCES = t-tap/test_downtime.c
t_tap_test_downtime_CPPFLAGS = $(T_TAP_AM_CPPFLAGS)
t_tap_test_downtime_LDADD = $(TAPLDADD)

t_tap_test_events_SOURCES = t-tap/test_events.c
t_tap_test_events_CPPFLAGS = $(T_TAP_AM_CPPFLAGS)
t_tap_test_events_LDADD = $(TAPLDADD)

dist_check_SCRIPTS = t/705naemonstats.t t/900-configparsing.t
check_PROGRAMS += t-tap/test_macros t-tap/test_timeperiods t-tap/test_checks \
t-tap/test_config t-tap/test_commands t-tap/test_downtime
t-tap/test_config t-tap/test_commands t-tap/test_downtime \
t-tap/test_events
distclean-local:
if test "${abs_srcdir}" != "${abs_builddir}"; then \
rm -r t; \
Expand Down

0 comments on commit 7dc5bbf

Please sign in to comment.