Skip to content

Commit b106b2b

Browse files
committed
update unit test programs to run with latest syslog-format plugin changes
1 parent c26c233 commit b106b2b

12 files changed

+76
-22
lines changed

src/plugin.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ plugin_load_module(const gchar *module_name, GlobalConfig *cfg, CfgArgs *args)
102102
gchar **module_path_dirs;
103103
gint i;
104104

105-
module_path = cfg_args_get(cfg->lexer->globals, "module-path");
105+
if (cfg->lexer)
106+
module_path = cfg_args_get(cfg->lexer->globals, "module-path");
107+
else
108+
module_path = NULL;
109+
106110
if (!module_path)
107111
module_path = PATH_PLUGINDIR;
108112

tests/unit/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
AM_CFLAGS = -I$(top_srcdir)/src
3+
AM_CFLAGS = -I$(top_srcdir)/src -I../../src
44
LIBS = @DEPS_LIBS@
55
LDADD = $(top_builddir)/src/libsyslog-ng.la
66

tests/unit/test_clone_logmsg.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "apphook.h"
55
#include "gsockaddr.h"
66
#include "logpipe.h"
7+
#include "cfg.h"
8+
#include "plugin.h"
79

810
#include <time.h>
911
#include <string.h>
@@ -21,7 +23,8 @@
2123
} \
2224
while (0)
2325

24-
LogParseOptions parse_options;
26+
MsgFormatOptions parse_options;
27+
GlobalConfig dummy_cfg;
2528

2629
unsigned long
2730
absolute_value(signed long diff)
@@ -170,7 +173,9 @@ main(int argc G_GNUC_UNUSED, char *argv[] G_GNUC_UNUSED)
170173
putenv("TZ=MET-1METDST");
171174
tzset();
172175

173-
log_parse_syslog_options_defaults(&parse_options);
176+
plugin_load_module("syslogformat", &dummy_cfg, NULL);
177+
msg_format_options_defaults(&parse_options);
178+
msg_format_options_init(&parse_options, &dummy_cfg);
174179

175180
testcase("<7>1 2006-10-29T01:59:59.156+01:00 mymachine.example.com evntslog - ID47 [exampleSDID@0 iut=\"3\" eventSource=\"Application\" eventID=\"1011\"][examplePriority@0 class=\"high\"] BOMAn application event log entry...",
176181
LP_SYSLOG_PROTOCOL, //flags

tests/unit/test_csvparser.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "apphook.h"
44
#include "csvparser/csvparser.h"
55
#include "misc.h"
6+
#include "cfg.h"
67

78
#include <time.h>
89
#include <string.h>
@@ -21,7 +22,8 @@
2122
} \
2223
while (0)
2324

24-
LogParseOptions parse_options;
25+
MsgFormatOptions parse_options;
26+
GlobalConfig dummy_cfg;
2527

2628
int
2729
testcase(gchar *msg, guint parse_flags, gint max_columns, guint32 flags, gchar *delimiters, gchar *quotes, gchar *null_value, gchar *first_value, ...)
@@ -126,7 +128,9 @@ main(int argc G_GNUC_UNUSED, char *argv[] G_GNUC_UNUSED)
126128
putenv("TZ=MET-1METDST");
127129
tzset();
128130

129-
log_parse_syslog_options_defaults(&parse_options);
131+
plugin_load_module("syslogformat", &dummy_cfg, NULL);
132+
msg_format_options_defaults(&parse_options);
133+
msg_format_options_init(&parse_options, &dummy_cfg);
130134

131135
testcase("<15> openvpn[2499]: PTHREAD support initialized", 0, -1, LOG_CSV_PARSER_ESCAPE_NONE, " ", NULL, NULL,
132136
"PTHREAD", "support", "initialized", NULL);

tests/unit/test_filters.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "filter.h"
44
#include "logmsg.h"
55
#include "apphook.h"
6+
#include "plugin.h"
67

78
#include <time.h>
89
#include <string.h>
@@ -11,7 +12,8 @@
1112

1213
int debug = 1;
1314
GSockAddr *sender_saddr;
14-
LogParseOptions parse_options;
15+
MsgFormatOptions parse_options;
16+
GlobalConfig dummy_cfg;
1517

1618
static gint
1719
facility_bits(gchar *fac)
@@ -201,7 +203,10 @@ main(int argc G_GNUC_UNUSED, char *argv[] G_GNUC_UNUSED)
201203

202204
app_startup();
203205

204-
log_parse_syslog_options_defaults(&parse_options);
206+
plugin_load_module("syslogformat", &dummy_cfg, NULL);
207+
msg_format_options_defaults(&parse_options);
208+
msg_format_options_init(&parse_options, &dummy_cfg);
209+
205210

206211
testcase("<15> openvpn[2499]: PTHREAD support initialized", filter_facility_new(facility_bits("user")), 1);
207212
testcase("<15> openvpn[2499]: PTHREAD support initialized", filter_facility_new(facility_bits("daemon")), 0);

tests/unit/test_logqueue.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#include "logqueue.h"
22
#include "logpipe.h"
33
#include "apphook.h"
4+
#include "plugin.h"
45

56
#include <stdlib.h>
67
#include <string.h>
78

89
int acked_messages = 0;
910
int fed_messages = 0;
10-
LogParseOptions parse_options;
11+
MsgFormatOptions parse_options;
12+
GlobalConfig dummy_cfg;
1113

1214
#define OVERFLOW_SIZE 10000
1315

@@ -208,7 +210,9 @@ main()
208210
putenv("TZ=MET-1METDST");
209211
tzset();
210212

211-
log_parse_syslog_options_defaults(&parse_options);
213+
plugin_load_module("syslogformat", &dummy_cfg, NULL);
214+
msg_format_options_defaults(&parse_options);
215+
msg_format_options_init(&parse_options, &dummy_cfg);
212216

213217
testcase_zero_diskbuf_alternating_send_acks();
214218
testcase_zero_diskbuf_and_normal_acks();

tests/unit/test_logwriter.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "apphook.h"
77
#include "cfg.h"
88
#include "timeutils.h"
9+
#include "plugin.h"
910

1011
#include <time.h>
1112
#include <stdlib.h>
@@ -14,7 +15,8 @@
1415

1516
gboolean success = TRUE;
1617
gboolean verbose = FALSE;
17-
LogParseOptions parse_options;
18+
MsgFormatOptions parse_options;
19+
GlobalConfig dummy_cfg;
1820

1921
LogMessage *
2022
init_msg(gchar *msg_string, gboolean use_syslog_protocol)
@@ -122,7 +124,12 @@ main(int argc G_GNUC_UNUSED, char *argv[] G_GNUC_UNUSED)
122124
putenv("TZ=MET-1METDST");
123125
tzset();
124126

125-
log_parse_syslog_options_defaults(&parse_options);
127+
plugin_load_module("syslogformat", &dummy_cfg, NULL);
128+
msg_format_options_defaults(&parse_options);
129+
msg_format_options_init(&parse_options, &dummy_cfg);
130+
131+
132+
msg_format_options_defaults(&parse_options);
126133
testcase(msg_syslog_str,NULL,TRUE,expeted_msg_syslog_str);
127134
testcase(msg_syslog_str,"$MSGID $MSG",TRUE,expeted_msg_syslog_str_t);
128135
testcase(msg_syslog_empty_str,NULL,TRUE,expected_msg_syslog_empty_str);

tests/unit/test_matcher.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#include "logmatcher.h"
22
#include "apphook.h"
3+
#include "plugin.h"
4+
#include "cfg.h"
35

46
#include <stdlib.h>
57
#include <string.h>
68

7-
LogParseOptions parse_options;
9+
MsgFormatOptions parse_options;
10+
GlobalConfig dummy_cfg;
811

912
int
1013
testcase_match(const gchar *log, const gchar *pattern, gint matcher_flags, gboolean expected_result, LogMatcher *m)
@@ -89,7 +92,9 @@ main()
8992
{
9093
app_startup();
9194

92-
log_parse_syslog_options_defaults(&parse_options);
95+
plugin_load_module("syslogformat", &dummy_cfg, NULL);
96+
msg_format_options_defaults(&parse_options);
97+
msg_format_options_init(&parse_options, &dummy_cfg);
9398

9499
/* POSIX regexp */
95100
testcase_replace("<155>2006-02-11T10:34:56+01:00 bzorp syslog-ng[23323]: árvíztűrőtükörfúrógép", "árvíz", "favíz", "favíztűrőtükörfúrógép", 0, log_matcher_posix_re_new());

tests/unit/test_msgparse.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "apphook.h"
55
#include "gsockaddr.h"
66
#include "timeutils.h"
7+
#include "cfg.h"
8+
#include "plugin.h"
79

810
#include <time.h>
911
#include <string.h>
@@ -21,7 +23,8 @@
2123
} \
2224
while (0)
2325

24-
LogParseOptions parse_options;
26+
MsgFormatOptions parse_options;
27+
GlobalConfig dummy_cfg;
2528

2629
unsigned long
2730
absolute_value(signed long diff)
@@ -140,7 +143,10 @@ main(int argc G_GNUC_UNUSED, char *argv[] G_GNUC_UNUSED)
140143
putenv("TZ=MET-1METDST");
141144
tzset();
142145

143-
log_parse_syslog_options_defaults(&parse_options);
146+
plugin_load_module("syslogformat", &dummy_cfg, NULL);
147+
msg_format_options_defaults(&parse_options);
148+
msg_format_options_init(&parse_options, &dummy_cfg);
149+
144150
testcase("<15> openvpn[2499]: PTHREAD support initialized", LP_EXPECT_HOSTNAME, NULL,
145151
15, // pri
146152
0, 0, 0, // timestamp (sec/usec/zone)

tests/unit/test_msgsdata.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
#include "logmsg.h"
22
#include "apphook.h"
3+
#include "cfg.h"
4+
#include "plugin.h"
35

46
#include <stdlib.h>
57
#include <string.h>
68

9+
MsgFormatOptions parse_options;
10+
GlobalConfig dummy_cfg;
11+
712
void
813
testcase_update(const gchar *msg, const gchar *expected_sd_str, gchar *elem_name1, ...)
914
{
1015
LogMessage *logmsg;
1116
GString *sd_str = g_string_new("");
1217
va_list va;
1318
gchar *elem, *param, *value;
14-
LogParseOptions parse_options;
1519

16-
log_parse_syslog_options_defaults(&parse_options);
1720
parse_options.flags |= LP_SYSLOG_PROTOCOL;
1821

1922
va_start(va, elem_name1);
@@ -51,6 +54,10 @@ main(int argc G_GNUC_UNUSED, char *argv[] G_GNUC_UNUSED)
5154
{
5255
app_startup();
5356

57+
plugin_load_module("syslogformat", &dummy_cfg, NULL);
58+
msg_format_options_defaults(&parse_options);
59+
msg_format_options_init(&parse_options, &dummy_cfg);
60+
5461
testcase_update("<132>1 2006-10-29T01:59:59.156+01:00 mymachine evntslog - - [exampleSDID@0 iut=\"3\" eventSource=\"Application\" eventID=\"1011\"][examplePriority@0 class=\"high\"] An application event log entry...",
5562
"[exampleSDID@0 iut=\"3\" eventSource=\"Application\" eventID=\"1011\"][examplePriority@0 class=\"high\"][meta sequenceId=\"11\"][syslog-ng param=\"value\"]",
5663
"meta", "sequenceId", "11",

tests/unit/test_template.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
gboolean success = TRUE;
1515
gboolean verbose = FALSE;
16-
LogParseOptions parse_options;
16+
MsgFormatOptions parse_options;
17+
GlobalConfig dummy_cfg;
1718

1819
void
1920
testcase(LogMessage *msg, gchar *template, gchar *expected)
@@ -51,7 +52,9 @@ main(int argc G_GNUC_UNUSED, char *argv[] G_GNUC_UNUSED)
5152
if (argc > 1)
5253
verbose = TRUE;
5354

54-
log_parse_syslog_options_defaults(&parse_options);
55+
plugin_load_module("syslogformat", &dummy_cfg, NULL);
56+
msg_format_options_defaults(&parse_options);
57+
msg_format_options_init(&parse_options, &dummy_cfg);
5558

5659
configuration = &dummy;
5760
dummy.version = 0x0201;

tests/unit/test_template_speed.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "apphook.h"
66
#include "cfg.h"
77
#include "timeutils.h"
8+
#include "plugin.h"
89

910
#include <time.h>
1011
#include <stdlib.h>
@@ -13,7 +14,8 @@
1314

1415
gboolean success = TRUE;
1516
gboolean verbose = FALSE;
16-
LogParseOptions parse_options;
17+
MsgFormatOptions parse_options;
18+
GlobalConfig dummy_cfg;
1719

1820
/* Beginning of Message character encoded in UTF8 */
1921
#define BOM "\xEF\xBB\xBF"
@@ -86,7 +88,9 @@ main(int argc G_GNUC_UNUSED, char *argv[] G_GNUC_UNUSED)
8688
putenv("TZ=MET-1METDST");
8789
tzset();
8890

89-
log_parse_syslog_options_defaults(&parse_options);
91+
plugin_load_module("syslogformat", &dummy_cfg, NULL);
92+
msg_format_options_defaults(&parse_options);
93+
msg_format_options_init(&parse_options, &dummy_cfg);
9094

9195
testcase("<155>2006-02-11T10:34:56.156+01:00 bzorp syslog-ng[23323]:árvíztűrőtükörfúrógép", FALSE,
9296
"<$PRI>$DATE $HOST $MSGHDR$MSG\n");

0 commit comments

Comments
 (0)