From: Florian Forster Date: Thu, 21 Dec 2023 09:29:08 +0000 (+0100) Subject: write_prometheus plugin: Add an initial (i.e. very simple) unit test. X-Git-Tag: 6.0.0-rc0~28^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f68413c29c63e6796813d0e3d33c7802955e07c;p=thirdparty%2Fcollectd.git write_prometheus plugin: Add an initial (i.e. very simple) unit test. --- diff --git a/Makefile.am b/Makefile.am index c41558c01..d21164184 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2307,6 +2307,15 @@ write_prometheus_la_SOURCES = src/write_prometheus.c write_prometheus_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBMICROHTTPD_CPPFLAGS) write_prometheus_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBMICROHTTPD_LDFLAGS) write_prometheus_la_LIBADD = $(BUILD_WITH_LIBMICROHTTPD_LIBS) + +test_plugin_write_prometheus_SOURCES = src/write_prometheus_test.c \ + src/write_prometheus.c +test_plugin_write_prometheus_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBMICROHTTPD_CPPFLAGS) +test_plugin_write_prometheus_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBMICROHTTPD_LDFLAGS) +test_plugin_write_prometheus_LDADD = libplugin_mock.la libavltree.la \ + $(BUILD_WITH_LIBMICROHTTPD_LIBS) +check_PROGRAMS += test_plugin_write_prometheus +TESTS += test_plugin_write_prometheus endif if BUILD_PLUGIN_WRITE_REDIS diff --git a/src/write_prometheus_test.c b/src/write_prometheus_test.c new file mode 100644 index 000000000..fcf8e92af --- /dev/null +++ b/src/write_prometheus_test.c @@ -0,0 +1,52 @@ +/** + * collectd - src/write_prometheus_test.c + * Copyright (C) 2023 Florian octo Forster + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Florian octo Forster + */ + +#include "collectd.h" + +#include "testing.h" +#include "daemon/metric.h" + +void format_metric_family(strbuf_t *buf, metric_family_t const *prom_fam); + +DEF_TEST(format_metric_family) { + strbuf_t got = STRBUF_CREATE; + + metric_family_t fam = { + .name = "unit.test", + }; + + format_metric_family(&got, &fam); + EXPECT_EQ_INT(0, got.pos); + + STRBUF_DESTROY(got); + return 0; +} + +int main(void) { + RUN_TEST(format_metric_family); + + END_TEST; +}