Skip to content

Commit

Permalink
Fix prometheus#146: Add tests for with_labels constructor
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Pop <popadrian1996@gmail.com>
  • Loading branch information
popadi committed Jul 9, 2023
1 parent 6e2173c commit 35f554b
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,14 @@ mod tests {

#[test]
fn constructors() {
let prefix = "test_prefix";
let counter_name = "test_counter";

let prefix = "test_prefix";
let labels = vec![
(Cow::Borrowed("global_label_1"), Cow::Borrowed("value_1")),
(Cow::Borrowed("global_label_1"), Cow::Borrowed("value_2")),
];

// test with_prefix constructor
let mut registry = Registry::with_prefix(prefix);
let counter: Counter = Counter::default();
registry.register(counter_name, "some help", counter);
Expand All @@ -557,10 +562,19 @@ mod tests {
.next()
);

let labels = vec![
(Cow::Borrowed("global_label_1"), Cow::Borrowed("value_1")),
(Cow::Borrowed("global_label_1"), Cow::Borrowed("value_2")),
];
// test with_labels constructor
let mut registry = Registry::with_labels(labels.clone().into_iter());
let counter: Counter = Counter::default();
registry.register(counter_name, "some help", counter);
assert_eq!(
Some((counter_name.to_string(), labels.clone())),
registry
.iter_metrics()
.map(|(desc, _)| (desc.name.clone(), desc.labels.clone()))
.next()
);

// test with_prefix_and_labels constructor
let mut registry = Registry::with_prefix_and_labels(prefix, labels.clone().into_iter());
let counter: Counter = Counter::default();
registry.register(counter_name, "some help", counter);
Expand Down

0 comments on commit 35f554b

Please sign in to comment.