]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
write_prometheus plugin: Add an initial (i.e. very simple) unit test.
authorFlorian Forster <octo@collectd.org>
Thu, 21 Dec 2023 09:29:08 +0000 (10:29 +0100)
committerFlorian Forster <octo@collectd.org>
Thu, 21 Dec 2023 11:59:59 +0000 (12:59 +0100)
Makefile.am
src/write_prometheus_test.c [new file with mode: 0644]

index c41558c01bb2ce91fe056c706ac1a87b648a6ede..d211641844ab5cd09c17f09f29f93c4970f0e33c 100644 (file)
@@ -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 (file)
index 0000000..fcf8e92
--- /dev/null
@@ -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 <octo at collectd.org>
+ */
+
+#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;
+}