tests: net: prometheus: Make sure formatter works as expected
Enhance the formatter test to verify that two metrics can be formatted. Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit is contained in:
parent
34ed76b185
commit
99abfda5ba
1 changed files with 12 additions and 3 deletions
|
@ -13,7 +13,9 @@
|
|||
#define MAX_BUFFER_SIZE 256
|
||||
|
||||
PROMETHEUS_COUNTER_DEFINE(test_counter, "Test counter",
|
||||
({ .key = "test", .value = "counter" }));
|
||||
({ .key = "test", .value = "counter" }), NULL);
|
||||
PROMETHEUS_COUNTER_DEFINE(test_counter2, "Test counter 2",
|
||||
({ .key = "test", .value = "counter" }), NULL);
|
||||
|
||||
PROMETHEUS_COLLECTOR_DEFINE(test_custom_collector);
|
||||
|
||||
|
@ -28,11 +30,15 @@ ZTEST(test_formatter, test_prometheus_formatter_simple)
|
|||
int ret;
|
||||
char formatted[MAX_BUFFER_SIZE] = { 0 };
|
||||
struct prometheus_counter *counter;
|
||||
char exposed[] = "# HELP test_counter Test counter\n"
|
||||
char exposed[] = "# HELP test_counter2 Test counter 2\n"
|
||||
"# TYPE test_counter2 counter\n"
|
||||
"test_counter2{test=\"counter\"} 1\n"
|
||||
"# HELP test_counter Test counter\n"
|
||||
"# TYPE test_counter counter\n"
|
||||
"test_counter{test=\"counter\"} 1\n";
|
||||
|
||||
prometheus_collector_register_metric(&test_custom_collector, &test_counter.base);
|
||||
prometheus_collector_register_metric(&test_custom_collector, &test_counter2.base);
|
||||
|
||||
counter = (struct prometheus_counter *)prometheus_collector_get_metric(
|
||||
&test_custom_collector, "test_counter");
|
||||
|
@ -44,13 +50,16 @@ ZTEST(test_formatter, test_prometheus_formatter_simple)
|
|||
ret = prometheus_counter_inc(&test_counter);
|
||||
zassert_ok(ret, "Error incrementing counter");
|
||||
|
||||
ret = prometheus_counter_inc(&test_counter2);
|
||||
zassert_ok(ret, "Error incrementing counter 2");
|
||||
|
||||
zassert_equal(counter->value, 1, "Counter value is not 1");
|
||||
|
||||
ret = prometheus_format_exposition(&test_custom_collector, formatted, sizeof(formatted));
|
||||
zassert_ok(ret, "Error formatting exposition data");
|
||||
|
||||
zassert_equal(strcmp(formatted, exposed), 0,
|
||||
"Exposition format is not as expected (expected \"%s\", got \"%s\")",
|
||||
"Exposition format is not as expected (expected\n\"%s\", got\n\"%s\")",
|
||||
exposed, formatted);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue