From: Timo Sirainen Date: Tue, 29 Nov 2022 19:03:40 +0000 (+0200) Subject: stats: unit tests - Parse settings one line at a time instead of as streams X-Git-Tag: 2.4.0~3062 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5215555fa6eb7a306d384eb7a7d94b3865947a3;p=thirdparty%2Fdovecot%2Fcore.git stats: unit tests - Parse settings one line at a time instead of as streams --- diff --git a/src/stats/test-client-reader.c b/src/stats/test-client-reader.c index e9eed0cb5b..08fda56283 100644 --- a/src/stats/test-client-reader.c +++ b/src/stats/test-client-reader.c @@ -44,11 +44,12 @@ bool test_stats_callback(struct event *event, return TRUE; } -static const char *settings_blob_1 = -"metric=test\n" -"metric/test/metric_name=test\n" -"metric/test/filter=event=test\n" -"\n"; +static const char *const settings_blob_1[] = { + "metric=test", + "metric/test/metric_name=test", + "metric/test/filter=event=test", + NULL +}; static int test_reader_server_input_args(struct connection *conn ATTR_UNUSED, const char *const *args) @@ -123,12 +124,13 @@ static void test_client_reader(void) test_end(); } -static const char *settings_blob_2 = -"metric=test\n" -"metric/test/metric_name=test\n" -"metric/test/filter=event=test\n" -"metric/test/group_by=test_name\n" -"\n"; +static const char *const settings_blob_2[] = { + "metric=test", + "metric/test/metric_name=test", + "metric/test/filter=event=test", + "metric/test/group_by=test_name", + NULL +}; static int test_reader_server_input_args_group_by(struct connection *conn, diff --git a/src/stats/test-client-writer.c b/src/stats/test-client-writer.c index 1256da9d30..a08e4c9f0a 100644 --- a/src/stats/test-client-writer.c +++ b/src/stats/test-client-writer.c @@ -97,11 +97,12 @@ bool test_stats_callback(struct event *event, return TRUE; } -static const char *settings_blob_1 = -"metric=test\n" -"metric/test/metric_name=test\n" -"metric/test/filter=event=test\n" -"\n"; +static const char *const settings_blob_1[] = { + "metric=test", + "metric/test/metric_name=test", + "metric/test/filter=event=test", + NULL +}; static void test_client_writer(void) { diff --git a/src/stats/test-stats-common.c b/src/stats/test-stats-common.c index de8185e51d..5b2947d368 100644 --- a/src/stats/test-stats-common.c +++ b/src/stats/test-stats-common.c @@ -19,25 +19,25 @@ time_t stats_startup_time; static bool callback_added = FALSE; -static struct stats_settings *read_settings(const char *settings) +static struct stats_settings *read_settings(const char *const settings[]) { - struct istream *is = test_istream_create(settings); const char *error; struct setting_parser_context *ctx = settings_parser_init(test_pool, &stats_setting_parser_info, 0); - if (settings_parse_stream_read(ctx, is) < 0) - i_fatal("Failed to parse settings: %s", - settings_parser_get_error(ctx)); + for (unsigned int i = 0; settings[i] != NULL; i++) { + if (settings_parse_line(ctx, settings[i]) <= 0) + i_fatal("Failed to parse settings: %s", + settings_parser_get_error(ctx)); + } if (!settings_parser_check(ctx, test_pool, &error)) i_fatal("Failed to parse settings: %s", error); struct stats_settings *set = settings_parser_get(ctx); settings_parser_unref(&ctx); - i_stream_unref(&is); return set; } -void test_init(const char *settings_blob) +void test_init(const char *const settings_blob[]) { if (!callback_added) { event_register_callback(test_stats_callback); diff --git a/src/stats/test-stats-common.h b/src/stats/test-stats-common.h index 86c03f4c8c..de3af69177 100644 --- a/src/stats/test-stats-common.h +++ b/src/stats/test-stats-common.h @@ -3,7 +3,6 @@ #include "stats-common.h" #include "event-filter.h" -#include "istream.h" #include "settings-parser.h" #include "str.h" #include "test-common.h" @@ -21,7 +20,7 @@ bool test_stats_callback(struct event *event, struct failure_context *ctx, const char *fmt ATTR_UNUSED, va_list args ATTR_UNUSED); -void test_init(const char *settings_blob); +void test_init(const char *const settings_blob[]); void test_deinit(void); void test_event_send(struct event *event); diff --git a/src/stats/test-stats-metrics.c b/src/stats/test-stats-metrics.c index c384014b63..3eacf43798 100644 --- a/src/stats/test-stats-metrics.c +++ b/src/stats/test-stats-metrics.c @@ -17,11 +17,12 @@ bool test_stats_callback(struct event *event, return TRUE; } -static const char *settings_blob_1 = -"metric=test\n" -"metric/test/metric_name=test\n" -"metric/test/filter=event=test\n" -"\n"; +static const char *const settings_blob_1[] = { + "metric=test", + "metric/test/metric_name=test", + "metric/test/filter=event=test", + NULL +}; static void test_stats_metrics(void) { @@ -44,11 +45,12 @@ static void test_stats_metrics(void) test_end(); } -static const char *settings_blob_2 = -"metric=test\n" -"metric/test/metric_name=test\n" -"metric/test/filter=(event=test AND test_field=value)\n" -"\n"; +static const char *const settings_blob_2[] = { + "metric=test", + "metric/test/metric_name=test", + "metric/test/filter=(event=test AND test_field=value)", + NULL +}; static void test_stats_metrics_filter(void) { @@ -165,11 +167,14 @@ static void test_stats_metrics_group_by_discrete_real(const struct discrete_test test_begin(t_strdup_printf("stats metrics (discrete group by) - %s", test->settings_blob)); - test_init(t_strdup_printf("metric=test\n" - "metric/test/metric_name=test\n" - "metric/test/filter=event=test\n" - "metric/test/group_by=%s\n" - "\n", test->settings_blob)); + const char *const settings[] = { + "metric=test", + "metric/test/metric_name=test", + "metric/test/filter=event=test", + t_strdup_printf("metric/test/group_by=%s", test->settings_blob), + NULL + }; + test_init(settings); for (i = 0; i < test->num_values; i++) { for (j = 0; j < test->num_values; j++) { @@ -341,11 +346,15 @@ static void test_stats_metrics_group_by_quantized_real(const struct quantized_te test_begin(t_strdup_printf("stats metrics (quantized group by) - %s", test->settings_blob)); - test_init(t_strdup_printf("metric=test\n" - "metric/test/metric_name=test\n" - "metric/test/filter=event=test\n" - "metric/test/group_by=test_name foobar:%s\n" - "\n", test->settings_blob)); + const char *const settings[] = { + "metric=test", + "metric/test/metric_name=test", + "metric/test/filter=event=test", + t_strdup_printf("metric/test/group_by=test_name foobar:%s", + test->settings_blob), + NULL + }; + test_init(settings); struct event *event;