1 /*
2  * Copyright (c) 2024 Mustafa Abdullah Kus, Sparse Technology
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/ztest.h>
8 
9 #include <zephyr/net/prometheus/counter.h>
10 #include <zephyr/net/prometheus/collector.h>
11 
12 PROMETHEUS_COUNTER_DEFINE(test_counter_m, "Test counter",
13 			  ({ .key = "test_counter", .value = "test" }), NULL);
14 
15 PROMETHEUS_COLLECTOR_DEFINE(test_custom_collector);
16 
17 /**
18  * @brief Test prometheus_counter_inc
19  *
20  * @details The test shall increment the counter value by 1 and check if the
21  * value is incremented correctly.
22  *
23  * @details The test shall register the counter to the collector and check if the
24  * counter is found in the collector.
25  */
ZTEST(test_collector,test_prometheus_collector_register)26 ZTEST(test_collector, test_prometheus_collector_register)
27 {
28 	int ret;
29 	struct prometheus_counter *counter;
30 
31 	prometheus_collector_register_metric(&test_custom_collector, &test_counter_m.base);
32 
33 	counter = (struct prometheus_counter *)prometheus_collector_get_metric(
34 		&test_custom_collector, "test_counter_m");
35 
36 	zassert_equal_ptr(counter, &test_counter_m,
37 			  "Counter not found in collector (expected %p, got %p)",
38 			  &test_counter_m, counter);
39 
40 	zassert_equal(test_counter_m.value, 0, "Counter value is not 0");
41 
42 	ret = prometheus_counter_inc(counter);
43 	zassert_ok(ret, "Error incrementing counter");
44 
45 	zassert_equal(counter->value, 1, "Counter value is not 1");
46 }
47 
48 ZTEST_SUITE(test_collector, NULL, NULL, NULL, NULL, NULL);
49