diff options
Diffstat (limited to 'exporting/tests/exporting_fixtures.c')
-rw-r--r-- | exporting/tests/exporting_fixtures.c | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/exporting/tests/exporting_fixtures.c b/exporting/tests/exporting_fixtures.c new file mode 100644 index 0000000000..9668e5ab2d --- /dev/null +++ b/exporting/tests/exporting_fixtures.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "test_exporting_engine.h" + +int setup_configured_engine(void **state) +{ + struct engine *engine = __mock_read_exporting_config(); + + *state = engine; + + return 0; +} + +int teardown_configured_engine(void **state) +{ + struct engine *engine = *state; + + struct instance *instance = engine->connector_root->instance_root; + free((void *)instance->config.destination); + free((void *)instance->config.name); + simple_pattern_free(instance->config.charts_pattern); + simple_pattern_free(instance->config.hosts_pattern); + free(instance); + + free(engine->connector_root); + + free((void *)engine->config.prefix); + free((void *)engine->config.hostname); + free(engine); + + return 0; +} + +int setup_rrdhost() +{ + localhost = calloc(1, sizeof(RRDHOST)); + + localhost->rrd_update_every = 1; + + localhost->tags = strdupz("TAG1=VALUE1 TAG2=VALUE2"); + + localhost->rrdset_root = calloc(1, sizeof(RRDSET)); + RRDSET *st = localhost->rrdset_root; + st->rrdhost = localhost; + strcpy(st->id, "chart_id"); + st->name = strdupz("chart_name"); + st->flags |= RRDSET_FLAG_ENABLED; + st->rrd_memory_mode |= RRD_MEMORY_MODE_SAVE; + st->update_every = 1; + + localhost->rrdset_root->dimensions = calloc(1, sizeof(RRDDIM)); + RRDDIM *rd = localhost->rrdset_root->dimensions; + rd->rrdset = st; + rd->id = strdupz("dimension_id"); + rd->name = strdupz("dimension_name"); + rd->last_collected_value = 123000321; + rd->last_collected_time.tv_sec = 15051; + rd->next = NULL; + + rd->state = calloc(1, sizeof(*rd->state)); + rd->state->query_ops.oldest_time = __mock_rrddim_query_oldest_time; + rd->state->query_ops.latest_time = __mock_rrddim_query_latest_time; + rd->state->query_ops.init = __mock_rrddim_query_init; + rd->state->query_ops.is_finished = __mock_rrddim_query_is_finished; + rd->state->query_ops.next_metric = __mock_rrddim_query_next_metric; + rd->state->query_ops.finalize = __mock_rrddim_query_finalize; + + return 0; +} + +int teardown_rrdhost() +{ + RRDDIM *rd = localhost->rrdset_root->dimensions; + free((void *)rd->name); + free((void *)rd->id); + free(rd->state); + free(rd); + + RRDSET *st = localhost->rrdset_root; + free((void *)st->name); + free(st); + + free((void *)localhost->tags); + free(localhost); + + return 0; +} + +int setup_initialized_engine(void **state) +{ + setup_configured_engine(state); + + struct engine *engine = *state; + init_connectors_in_tests(engine); + + setup_rrdhost(); + + return 0; +} + +int teardown_initialized_engine(void **state) +{ + struct engine *engine = *state; + + teardown_rrdhost(); + buffer_free(engine->connector_root->instance_root->buffer); + teardown_configured_engine(state); + + return 0; +} |