]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
Added unit test for metric_reset.
authorelene-margalit <elene.margalit@gmail.com>
Mon, 17 Aug 2020 15:33:22 +0000 (17:33 +0200)
committerelene-margalit <elene.margalit@gmail.com>
Mon, 17 Aug 2020 15:33:22 +0000 (17:33 +0200)
src/daemon/metric_test.c

index 12816204609d74f13584b9aeaa3f738a3e3bee27..174f51c3c7bec22ea6fcb36c81b8eda5d0ca9f3f 100644 (file)
@@ -25,7 +25,6 @@
  */
 
 #include "collectd.h"
-
 #include "metric.h"
 #include "testing.h"
 
@@ -260,10 +259,44 @@ DEF_TEST(metric_family_append) {
   return 0;
 }
 
+DEF_TEST(metric_reset) {
+  struct {
+    value_t value;
+  } cases[] = {
+      {
+          .value.distribution = distribution_new_linear(10, 25),
+      },
+      {
+          .value.distribution = distribution_new_exponential(10, 3, 2),
+      },
+      {
+          .value.distribution =
+              distribution_new_custom(6, (double[]){5, 10, 20, 30, 50}),
+      },
+  };
+
+  metric_family_t m_fam = {
+      .type = METRIC_TYPE_DISTRIBUTION,
+  };
+  metric_family_t *metric_fam = &m_fam;
+
+  for (size_t i = 0; i < (sizeof(cases) / sizeof(cases[0])); i++) {
+    printf("## Case %zu: \n", i);
+
+    metric_t m = {
+        .family = metric_fam,
+        .value.distribution = cases[i].value.distribution,
+    };
+
+    EXPECT_EQ_INT(metric_reset(&m), 0);
+  }
+  return 0;
+}
+
 int main(void) {
   RUN_TEST(metric_label_set);
   RUN_TEST(metric_identity);
   RUN_TEST(metric_family_append);
-
+  RUN_TEST(metric_reset);
   END_TEST;
 }