From: Timo Sirainen Date: Fri, 21 Apr 2023 11:47:30 +0000 (+0300) Subject: stats: Convert unit tests to initialize settings with the new settings API X-Git-Tag: 2.4.0~2056 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=65fcc8a29eb4d9eb7211a39f1312529d13ce4c4e;p=thirdparty%2Fdovecot%2Fcore.git stats: Convert unit tests to initialize settings with the new settings API --- diff --git a/src/stats/test-stats-common.c b/src/stats/test-stats-common.c index 65939a61f8..bc9551ce6e 100644 --- a/src/stats/test-stats-common.c +++ b/src/stats/test-stats-common.c @@ -1,6 +1,7 @@ /* Copyright (c) 2019 Dovecot authors, see the included COPYING file */ #include "test-stats-common.h" +#include "settings.h" #include #include @@ -18,23 +19,27 @@ const struct master_service_ssl_settings *master_ssl_set = NULL; struct stats_metrics *stats_metrics = NULL; time_t stats_startup_time; +static struct stats_settings *stats_set; +static struct settings_root *set_root; static bool callback_added = FALSE; static struct stats_settings *read_settings(const char *const settings[]) { const char *error; - struct setting_parser_context *ctx = - settings_parser_init(test_pool, &stats_setting_parser_info, 0); + + set_root = settings_root_init(); 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)); + const char *key, *value; + t_split_key_value_eq(settings[i], &key, &value); + settings_root_override(set_root, key, value, + SETTINGS_OVERRIDE_TYPE_CODE); } - if (!settings_parser_check(ctx, test_pool, NULL, &error)) - i_fatal("Failed to parse settings: %s", - error); - struct stats_settings *set = settings_parser_get_set(ctx); - settings_parser_unref(&ctx); + struct stats_settings *set; + struct event *event = event_create(NULL); + event_set_ptr(event, SETTINGS_EVENT_ROOT, set_root); + if (settings_get(event, &stats_setting_parser_info, 0, &set, &error) < 0) + i_fatal("%s", error); + event_unref(&event); return set; } @@ -53,13 +58,15 @@ void test_init(const char *const settings_blob[]) stats_event_category_register(test_category.name, NULL); stats_event_category_register(child_test_category.name, &test_category); - struct stats_settings *set = read_settings(settings_blob); - stats_metrics = stats_metrics_init(set); + stats_set = read_settings(settings_blob); + stats_metrics = stats_metrics_init(stats_set); } void test_deinit(void) { stats_metrics_deinit(&stats_metrics); + settings_free(stats_set); + settings_root_deinit(&set_root); stats_event_categories_deinit(); pool_unref(&test_pool); }