Skip to content

Commit

Permalink
test: add test for using empty struct as histogram family labels
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerlevine committed Oct 31, 2023
1 parent 059da5d commit 1f3923a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/encoding/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ mod tests {
use crate::metrics::{counter::Counter, exemplar::CounterWithExemplar};
use pyo3::{prelude::*, types::PyModule};
use std::borrow::Cow;
use std::fmt::Error;

#[test]
fn encode_counter() {
Expand Down Expand Up @@ -764,6 +765,33 @@ mod tests {
parse_with_python_client(encoded);
}

#[test]
fn encode_histogram_family_with_empty_struct_family_labels() {
let mut registry = Registry::default();
let family =
Family::new_with_constructor(|| Histogram::new(exponential_buckets(1.0, 2.0, 10)));
registry.register("my_histogram", "My histogram", family.clone());

#[derive(Eq, PartialEq, Hash, Debug, Clone)]
struct EmptyLabels {}

impl EncodeLabelSet for EmptyLabels {
fn encode(&self, _encoder: crate::encoding::LabelSetEncoder) -> Result<(), Error> {
Ok(())
}
}

family
.get_or_create(&EmptyLabels {})
.observe(1.0);

let mut encoded = String::new();

encode(&mut encoded, &registry).unwrap();

parse_with_python_client(encoded);
}

#[test]
fn encode_histogram_with_exemplars() {
let mut registry = Registry::default();
Expand Down

0 comments on commit 1f3923a

Please sign in to comment.