]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
stats: unit tests - Parse settings one line at a time instead of as streams
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 29 Nov 2022 19:03:40 +0000 (21:03 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 27 Jan 2023 13:01:47 +0000 (13:01 +0000)
src/stats/test-client-reader.c
src/stats/test-client-writer.c
src/stats/test-stats-common.c
src/stats/test-stats-common.h
src/stats/test-stats-metrics.c

index e9eed0cb5bee1f1be4f266a94fb5c845c9645224..08fda5628309757939c399d8129eafece887d16c 100644 (file)
@@ -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,
index 1256da9d3079a22f0f0a9a954f1d30b87c57052b..a08e4c9f0a480be33d43a6cc77ac47f293c7103f 100644 (file)
@@ -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)
 {
index de8185e51d8176339994d8c95742ac6be34b8224..5b2947d36891707b5399b0fa39dd04b6f6d6ddd2 100644 (file)
@@ -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);
index 86c03f4c8c76cfe3c04e04fca69f03e0f47f59bc..de3af69177a2593f6ae00e321a5126e8601133c2 100644 (file)
@@ -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);
index c384014b63b6036266d58c0b04e352a092475a5b..3eacf437985ced3e80a2e9c366af99d6bb418058 100644 (file)
@@ -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;